Struct lazy_init::Lazy
[−]
[src]
pub struct Lazy<T> where
T: Sync, { /* fields omitted */ }
Lazy<T>
is a lazily initialized synchronized holder type. You can think
of it as a LazyTransform
where the initial type doesn't exist.
Methods
impl<T> Lazy<T> where
T: Sync,
[src]
T: Sync,
fn new() -> Lazy<T>
[src]
Construct a new, uninitialized Lazy<T>
.
fn get_or_create<F>(&self, f: F) -> &T where
F: FnOnce() -> T,
[src]
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!
fn get(&self) -> Option<&T>
[src]
Get a reference to the contained value, returning Some(ref)
if the
Lazy<T>
has been initialized or None
if it has not. It is
guaranteed that if a reference is returned it is to the value inside
the Lazy<T>
.
fn into_inner(self) -> Option<T>
[src]
Unwrap the contained value, returning Some
if the Lazy<T>
has been initialized
or None
if it has not.
Trait Implementations
impl<T> Default for Lazy<T> where
T: Sync,
[src]
T: Sync,