pub struct Lazy<T> { /* private fields */ }
Expand description
Lazy<T>
is a lazily initialized synchronized holder type. You can think
of it as a LazyTransform
where the initial type doesn’t exist.
Implementations§
Source§impl<T> Lazy<T>
impl<T> Lazy<T>
Sourcepub fn get_or_create<F>(&self, f: F) -> &Twhere
F: FnOnce() -> T,
pub fn get_or_create<F>(&self, f: F) -> &Twhere
F: FnOnce() -> T,
Get a reference to the contained value, invoking f
to create it
if the Lazy<T>
is uninitialized. It is guaranteed that if multiple
calls to get_or_create
race, only one will invoke its closure, and
every call will receive a reference to the newly created value.
The value stored in the Lazy<T>
is immutable after the closure returns
it, so think carefully about what you want to put inside!
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Lazy<T>
impl<T> !RefUnwindSafe for Lazy<T>
impl<T> Send for Lazy<T>where
T: Send,
impl<T> Sync for Lazy<T>
impl<T> Unpin for Lazy<T>where
T: Unpin,
impl<T> UnwindSafe for Lazy<T>where
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