pub struct OnceLockDefault<T> { /* private fields */ }Expand description
A OnceLock that returns a default value if it has not been set yet.
Implementations§
Source§impl<T> OnceLockDefault<T>
impl<T> OnceLockDefault<T>
Sourcepub const fn new(default: T) -> Self
pub const fn new(default: T) -> Self
Creates a new OnceLockDefault with the given default value.
Sourcepub fn set(&self, value: T) -> Result<(), T>
pub fn set(&self, value: T) -> Result<(), T>
Initializes the contents of the cell to value.
May block if another thread is currently attempting to initialize the cell. The cell is guaranteed to contain a value when set returns, though not necessarily the one provided.
§Errors
Returns Ok(()) if the cell was uninitialized and Err(value) if the cell was already initialized.
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Gets the reference to the underlying value, if set. Otherwise returns a reference to the default value.
This method never blocks.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Checks if the cell has been initialized.
This method never blocks.
Trait Implementations§
Source§impl<T: Clone> Clone for OnceLockDefault<T>
impl<T: Clone> Clone for OnceLockDefault<T>
Source§fn clone(&self) -> OnceLockDefault<T>
fn clone(&self) -> OnceLockDefault<T>
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl<T: Debug> Debug for OnceLockDefault<T>
impl<T: Debug> Debug for OnceLockDefault<T>
Auto Trait Implementations§
impl<T> !Freeze for OnceLockDefault<T>
impl<T> RefUnwindSafe for OnceLockDefault<T>where
T: RefUnwindSafe + UnwindSafe,
impl<T> Send for OnceLockDefault<T>where
T: Send,
impl<T> Sync for OnceLockDefault<T>
impl<T> Unpin for OnceLockDefault<T>where
T: Unpin,
impl<T> UnwindSafe for OnceLockDefault<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