Struct OnceNonZeroUsize

struct OnceNonZeroUsize { ... }

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

Implementations

impl OnceNonZeroUsize

const fn new() -> Self

Creates a new empty cell.

fn get(self: &Self) -> Option<NonZeroUsize>

Gets the underlying value.

unsafe fn get_unchecked(self: &Self) -> NonZeroUsize

Get the reference to the underlying value, without checking if the cell is initialized.

Safety

Caller must ensure that the cell is in initialized state, and that the contents are acquired by (synchronized to) this thread.

fn set(self: &Self, value: NonZeroUsize) -> Result<(), ()>

Sets the contents of this cell to value.

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

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

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<NonZeroUsize, E>
where
    F: FnOnce() -> Result<NonZeroUsize, 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 Debug for OnceNonZeroUsize

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

impl Default for OnceNonZeroUsize

fn default() -> OnceNonZeroUsize

impl Freeze for OnceNonZeroUsize

impl RefUnwindSafe for OnceNonZeroUsize

impl Send for OnceNonZeroUsize

impl Sync for OnceNonZeroUsize

impl Unpin for OnceNonZeroUsize

impl UnsafeUnpin for OnceNonZeroUsize

impl UnwindSafe for OnceNonZeroUsize

impl<T> Any for OnceNonZeroUsize

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for OnceNonZeroUsize

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

impl<T> BorrowMut for OnceNonZeroUsize

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

impl<T> From for OnceNonZeroUsize

fn from(t: T) -> T

Returns the argument unchanged.

impl<T, U> Into for OnceNonZeroUsize

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 OnceNonZeroUsize

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

impl<T, U> TryInto for OnceNonZeroUsize

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