pub struct OnceMut<T> { /* private fields */ }Expand description
Like OnceCell but with exclusive mutable access to its content.
Implementations§
Source§impl<T> OnceMut<T>
impl<T> OnceMut<T>
Sourcepub fn set(&self, value: T) -> Result<(), T>
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.
Sourcepub fn set_with<F: FnOnce() -> T>(&self, ctor: F) -> Result<(), F>
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.
Sourcepub fn take(&mut self) -> Option<T>
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.
Sourcepub fn get_ptr(&self) -> Option<*mut T>
pub fn get_ptr(&self) -> Option<*mut T>
Gets the pointer to the underlying value.
Returns None if the cell is empty.
Sourcepub fn get_mut(&self) -> Option<&mut T>
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.
Sourcepub fn lock(&self) -> Option<LockGuard<'_, T>>
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.
Sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
Consumes the cell, returning the wrapped value.
Returns None if the cell was empty.