Struct async_once_cell::future::OnceCell[][src]

pub struct OnceCell<T> { /* fields omitted */ }
Expand description

A thread-safe cell which can be written to only once.

This allows initialization using an async closure which is guaranteed to only be called once.

Implementations

Creates a new empty cell.

Gets the contents of the cell, initializing it with init if the cell was empty.

Many tasks may call get_or_init concurrently with different initializing futures, but it is guaranteed that only one future will be executed as long as the resuting future is polled to completion.

If f panics, the panic is propagated to the caller, and the cell remains uninitialized.

If the Future returned by this function is dropped prior to completion, the cell remains uninitialized (and another init futures may be selected for polling).

It is an error to reentrantly initialize the cell from init. The current implementation deadlocks, but will recover if the offending task is dropped.

Gets the contents of the cell, initializing it with init if the cell was empty. If the cell was empty and f failed, an error is returned.

If f panics, the panic is propagated to the caller, and the cell remains uninitialized.

If the Future returned by this function is dropped prior to completion, the cell remains uninitialized.

It is an error to reentrantly initialize the cell from init. The current implementation deadlocks, but will recover if the offending task is dropped.

Gets the reference to the underlying value.

Returns None if the cell is empty or being initialized. This method never blocks.

Gets a mutable reference to the underlying value.

Takes the value out of this OnceCell, moving it back to an uninitialized state.

Consumes the OnceCell, returning the wrapped value. Returns None if the cell was empty.

Trait Implementations

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.