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.
Trait Implementations§
Auto Trait Implementations§
impl<T, F = fn() -> T> !Freeze for LazyLock<T, F>
impl<T, F = fn() -> T> !RefUnwindSafe for LazyLock<T, F>
impl<T, F> Send for LazyLock<T, F>
impl<T, F> Unpin for LazyLock<T, F>
impl<T, F> UnwindSafe for LazyLock<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more