OnceMut

Struct OnceMut 

Source
pub struct OnceMut<T> { /* private fields */ }
Expand description

Like OnceCell but with exclusive mutable access to its content.

Implementations§

Source§

impl<T> OnceMut<T>

Source

pub const fn new() -> Self

Creates a new empty cell.

Source

pub fn set(&self, value: T) -> Result<(), T>

Sets the contents of this cell to value.

Returns Ok(()) if the cell’s value was set by this call.

Source

pub fn set_with<F: FnOnce() -> T>(&self, ctor: F) -> Result<(), F>

Sets the contents of this cell to value returned by ctor call.

The ctor is called only if the cell’s value is going set by this call. Otherwice ctor returned in Err(..).

§Panics

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

Source

pub fn take(&mut self) -> Option<T>

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

Has no effect and returns None if the cell hasn’t been initialized.

Source

pub fn get_ptr(&self) -> Option<*mut T>

Gets the pointer to the underlying value.

Returns None if the cell is empty.

Source

pub fn get_mut(&self) -> Option<&mut T>

Gets the mutable reference to the underlying value.

The main difference from OnceCell::get_mut is that self is taken as immutable.

After this call returns Some(..), all subsequent calls will return None, and there is no way to obtain mutable reference again.

Source

pub fn lock(&self) -> Option<LockGuard<'_, T>>

Gets a guarded mutable reference to the underlying value.

Only one guard of the same value can exist at the same time.

Source

pub fn into_inner(self) -> Option<T>

Consumes the cell, returning the wrapped value.

Returns None if the cell was empty.

Auto Trait Implementations§

§

impl<T> !Freeze for OnceMut<T>

§

impl<T> RefUnwindSafe for OnceMut<T>

§

impl<T> Send for OnceMut<T>
where T: Send,

§

impl<T> Sync for OnceMut<T>
where T: Send,

§

impl<T> Unpin for OnceMut<T>
where T: Unpin,

§

impl<T> UnwindSafe for OnceMut<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.