pub struct Lazy<T, B, F = fn() -> T> { /* private fields */ }
Expand description

A type for lazy initialization of e.g. global static variables, which provides the same functionality as the lazy_static! macro.

Implementations

Creates a new uninitialized Lazy with the given init closure.

Examples

The init argument can be a simple function pointer or any FnOnce closure.

use conquer_once::Lazy;

static LAZY_1: Lazy<Vec<i32>> = Lazy::new(|| vec![1, 2, 3, 4, 5]);
static LAZY_2: Lazy<Vec<i32>> = Lazy::new(Vec::<i32>::new);

Returns true if the Lazy has been successfully initialized.

Returns true if the Lazy has been poisoned.

Returns a reference to the already initialized inner value or initializes it first.

This has the same effect as using the Deref operator on a Lazy.

Panics

This method panics if the init procedure specified during construction panics or if the Lazy is poisoned.

Trait Implementations

Performs the conversion.

Immutably borrows from an owned value. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. 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 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.