pub struct LazyLock<T, F = fn() -> T> { /* private fields */ }
Expand description
The LazyLock
is a synchronization primitive that allows for
initializing a value once, and allowing others to obtain a
reference to the value. This is useful for lazy initialization of
a static value.
§Example
use futures_executor::block_on;
use embassy_sync::lazy_lock::LazyLock;
// Define a static value that will be lazily initialized
// at runtime at the first access.
static VALUE: LazyLock<u32> = LazyLock::new(|| 20);
let reference = VALUE.get();
assert_eq!(reference, &20);
Implementations§
Source§impl<T, F: FnOnce() -> T> LazyLock<T, F>
impl<T, F: FnOnce() -> T> LazyLock<T, F>
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Get a reference to the underlying value, initializing it if it has not been done already.
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the LazyLock
, returning the underlying value. The
initialization function will be called if it has not been
already.