Struct lazy_rc::LazyRc

source ·
pub struct LazyRc<T> { /* private fields */ }
Expand description

A single-threaded reference-counting pointer, akin to Rc<T>, but with lazy initialization

Implementations§

Create a new LazyArc<T> that is initially empty. It’s “inner” value will be initialized on first access!

Create a new LazyArc<T> that is already initialized to value.

Create a new LazyArc<T> that is already initialized to the given Rc<T> pointer.

Returns true, if and only if th “inner” value is initialized.

Returns a pointer to the existing “inner” value, or initializes the value right now.

If and only if the “inner” value is not initialized yet, the function init_fn() is called to create the value. The “inner” value is then set to the return value of init_fn() and a new Rc<T> pointer to the “inner” value is returned.

Returns a pointer to the existing “inner” value, or tries to initializes the value right now.

If and only if the “inner” value is not initialized yet, the function init_fn() is called to create the value. In case that init_fn() returns an error, that error is passed through and the “inner” value remains in the uninitialized state for now. If the “inner” value already existed or if it was created successfully just now, a new Rc<T> pointer to the “inner” value is returned.

Applies function map_fn() to the “inner”, if already initialized.

If and only if the “inner” value already is initialize, the function map_fn() is called with a reference to the “inner” value and its return value is passed through. Otherwise the function map_fn() is not called and None is returned.

Returns a pointer to the “inner” value, if already initialized.

If and only if the “inner” value already is initialized, the function returns a new Rc<T> pointer to the “inner” value. Otherwise, if the “inner” value is not initialized yet, the value remains in the uninitialized state and the function returns None.

Takes the “inner” value out of this LazyRc<T> instance, if already initialized.

If and only if the “inner” value already is initialized, the function returns the Rc<T> pointer to the current “inner” value and resets this LazyRc<T> instance’ “inner” value to the uninitialized state. Otherwise, the function simply returns None.

Trait Implementations§

Creates a clone of this LazyRc<T> instance.

If the “inner” value of this instance is already initialized, the clone will be pointing to the same “inner” value, i.e. the “inner” value is not cloned. Otherwise, the clone will initially be empty; it can be initialized independently from this instance.

Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

The default value is a new empty LazyRc<T> instance.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.