Struct try_lazy_init::Lazy[][src]

pub struct Lazy<T> { /* fields omitted */ }
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

Construct a new, uninitialized Lazy<T>.

Unwrap the contained value, returning Some if the Lazy<T> has been initialized or None if it has not.

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!

Tries to 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 successfully 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 succeeds and returns it, so think carefully about what you want to put inside!

Errors

Iff f returns a Result::Err, this error is returned verbatim.

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>.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.