Struct OnceRef

struct OnceRef<'a, T> { ... }

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

Implementations

impl<'a, T> OnceRef<'a, T>

const fn new() -> Self

Creates a new empty cell.

fn get(self: &Self) -> Option<&'a T>

Gets a reference to the underlying value.

fn set(self: &Self, value: &'a T) -> Result<(), ()>

Sets the contents of this cell to value.

Returns Ok(()) if the cell was empty and Err(value) if it was full.

fn get_or_init<F>(self: &Self, f: F) -> &'a T
where
    F: FnOnce() -> &'a T

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

If several threads concurrently run get_or_init, more than one f can be called. However, all threads will return the same value, produced by some f.

fn get_or_try_init<F, E>(self: &Self, f: F) -> Result<&'a T, E>
where
    F: FnOnce() -> Result<&'a T, E>

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

If several threads concurrently run get_or_init, more than one f can be called. However, all threads will return the same value, produced by some f.

impl<'a, T> Debug for OnceRef<'a, T>

fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result

impl<'a, T> Default for OnceRef<'a, T>

fn default() -> Self

impl<'a, T> Freeze for OnceRef<'a, T>

impl<'a, T> RefUnwindSafe for OnceRef<'a, T>

impl<'a, T> Send for OnceRef<'a, T>

impl<'a, T> Unpin for OnceRef<'a, T>

impl<'a, T> UnsafeUnpin for OnceRef<'a, T>

impl<'a, T> UnwindSafe for OnceRef<'a, T>

impl<'a, T: Sync> Sync for OnceRef<'a, T>

impl<T> Any for OnceRef<'a, T>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for OnceRef<'a, T>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for OnceRef<'a, T>

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> From for OnceRef<'a, T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for OnceRef<'a, T>

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for OnceRef<'a, T>

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for OnceRef<'a, T>

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>