Struct mycelium_util::sync::once::Lazy
source · pub struct Lazy<T, F = fn() -> T> { /* private fields */ }
Expand description
A cell which will be lazily initialized by the provided function the first time it is accessed.
This can be used as a safer alternative to static mut
.
Implementations§
source§impl<T, F> Lazy<T, F>
impl<T, F> Lazy<T, F>
sourcepub const fn new(initializer: F) -> Lazy<T, F>
Available on non-loom
only.
pub const fn new(initializer: F) -> Lazy<T, F>
loom
only.Returns a new Lazy
cell, initialized with the provided initializer
function.
sourcepub fn get_if_present(&self) -> Option<&T>
pub fn get_if_present(&self) -> Option<&T>
Returns the value of the lazy cell, if it has already been initialized.
Otherwise, returns None
.
Trait Implementations§
impl<T, F> Send for Lazy<T, F>
impl<T, F> Sync for Lazy<T, F>
Auto Trait Implementations§
impl<T, F = fn() -> T> !Freeze for Lazy<T, F>
impl<T, F = fn() -> T> !RefUnwindSafe for Lazy<T, F>
impl<T, F> Unpin for Lazy<T, F>
impl<T, F> UnwindSafe for Lazy<T, F>where
F: UnwindSafe,
T: 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