pub struct OptionCell<T> { /* private fields */ }
Expand description
An equivalent of std::cell::OnceCell or once_cell::unsync::OnceCell with an additional transmute helper. To guarantee the helper’s safety, it is defined as a different type from the original OnceCell.
Implementations§
Source§impl<T> OptionCell<T>
impl<T> OptionCell<T>
Sourcepub fn get(&self) -> Option<&T>
pub fn get(&self) -> Option<&T>
Gets the reference to the underlying value.
Returns None
if the cell is empty.
Sourcepub fn get_mut(&mut self) -> &mut Option<T>
pub fn get_mut(&mut self) -> &mut Option<T>
Gets the mutable reference to the underlying Option.
Unlike the original OnceCell, this method returns a mutable reference to the whole Option
Sourcepub fn get_or_init<F>(&self, f: F) -> &Twhere
F: FnOnce() -> T,
pub fn get_or_init<F>(&self, f: F) -> &Twhere
F: FnOnce() -> T,
Gets the contents of the cell, initializing with f
if the cell was empty.
Sourcepub fn into_inner(self) -> Option<T>
pub fn into_inner(self) -> Option<T>
Consumes the cell, returning the wrapped Option
Sourcepub fn from_mut(slice: &mut Option<T>) -> &mut Self
pub fn from_mut(slice: &mut Option<T>) -> &mut Self
Converts an existing mutable reference into OptionCell.
Sourcepub fn from_mut_slice(slice: &mut [Option<T>]) -> &mut [Self]
pub fn from_mut_slice(slice: &mut [Option<T>]) -> &mut [Self]
Converts an existing mutable slice into a slice of OptionCell.
Trait Implementations§
Source§impl<T> Clone for OptionCell<T>where
T: Clone,
impl<T> Clone for OptionCell<T>where
T: Clone,
Source§impl<T> Debug for OptionCell<T>where
T: Debug,
impl<T> Debug for OptionCell<T>where
T: Debug,
Source§impl<T> Default for OptionCell<T>
impl<T> Default for OptionCell<T>
Source§impl<T> From<Option<T>> for OptionCell<T>
impl<T> From<Option<T>> for OptionCell<T>
Source§impl<T> From<OptionCell<T>> for Option<T>
impl<T> From<OptionCell<T>> for Option<T>
Source§fn from(cell: OptionCell<T>) -> Self
fn from(cell: OptionCell<T>) -> Self
Converts to this type from the input type.
Source§impl<T> PartialEq for OptionCell<T>where
T: PartialEq<T>,
impl<T> PartialEq for OptionCell<T>where
T: PartialEq<T>,
Auto Trait Implementations§
impl<T> !Freeze for OptionCell<T>
impl<T> !RefUnwindSafe for OptionCell<T>
impl<T> Send for OptionCell<T>where
T: Send,
impl<T> !Sync for OptionCell<T>
impl<T> Unpin for OptionCell<T>where
T: Unpin,
impl<T> UnwindSafe for OptionCell<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