pub struct OnceCell<T>(/* private fields */);
Expand description
An Option
value which can be safely written once.
Implementations§
Source§impl<T> OnceCell<T>
impl<T> OnceCell<T>
Sourcepub fn get_mut(&mut self) -> Option<&mut T>
pub fn get_mut(&mut self) -> Option<&mut T>
Get a mutable reference to the contained value, if any.
Sourcepub fn get_or_init(&self, init: impl FnOnce() -> T) -> &T
pub fn get_or_init(&self, init: impl FnOnce() -> T) -> &T
Get a reference to the contained value, initializing it if necessary. The initializer will only be run by one thread if multiple are in competition.
Sourcepub fn get_or_try_init<E>(
&self,
init: impl FnOnce() -> Result<T, E>,
) -> Result<&T, E>
pub fn get_or_try_init<E>( &self, init: impl FnOnce() -> Result<T, E>, ) -> Result<&T, E>
Get a reference to the contained value, initializing it if necessary. The initializer will only be run by one thread if multiple are in competition.
Sourcepub fn set(&self, value: T) -> Result<(), T>
pub fn set(&self, value: T) -> Result<(), T>
Assign the value of the OnceCell, returning Some(value)
if
the cell is already locked or populated.
Sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
Extract the inner value.
Trait Implementations§
Source§impl<T> From<OptionLock<T>> for OnceCell<T>
impl<T> From<OptionLock<T>> for OnceCell<T>
Source§fn from(lock: OptionLock<T>) -> Self
fn from(lock: OptionLock<T>) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl<T> !Freeze for OnceCell<T>
impl<T> !RefUnwindSafe for OnceCell<T>
impl<T> Send for OnceCell<T>where
T: Send,
impl<T> Sync for OnceCell<T>where
T: Send,
impl<T> Unpin for OnceCell<T>where
T: Unpin,
impl<T> UnwindSafe for OnceCell<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more