pub struct OnceLock<T, O: Once> { /* private fields */ }Expand description
A synchronization primitive which can nominally be written to only once.
Implementations§
Source§impl<T, O: Once> OnceLock<T, O>
impl<T, O: Once> OnceLock<T, O>
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, or being initialized. This method
never blocks.
Sourcepub fn get_or_init<F: FnOnce() -> T>(&self, f: F) -> &T
pub fn get_or_init<F: FnOnce() -> T>(&self, f: F) -> &T
Gets the contents of the cell, initializing it with f if the cell
was empty.
Many threads may call get_or_init concurrently with different
initializing functions, but it is guaranteed that only one function
will be executed.
§Panics
Panics if f panics. If f panics, the cell is left uninitialized and
subsequent attempts to initialize the cell are expected to panic.
Trait Implementations§
impl<T: Eq, O: Once> Eq for OnceLock<T, O>
impl<T: Send, O: Once> Send for OnceLock<T, O>
impl<T: Send + Sync, O: Once> Sync for OnceLock<T, O>
Auto Trait Implementations§
impl<T, O> !Freeze for OnceLock<T, O>
impl<T, O> !RefUnwindSafe for OnceLock<T, O>
impl<T, O> Unpin for OnceLock<T, O>
impl<T, O> UnsafeUnpin for OnceLock<T, O>
impl<T, O> UnwindSafe for OnceLock<T, O>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<B, A> LockBefore<B> for Awhere
B: LockAfter<A>,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<L, T> UnlockedAccess<L> for Twhere
L: UnlockedAccessMarkerFor<T>,
impl<L, T> UnlockedAccess<L> for Twhere
L: UnlockedAccessMarkerFor<T>,
Source§type Data = <L as UnlockedAccessMarkerFor<T>>::Data
type Data = <L as UnlockedAccessMarkerFor<T>>::Data
The type of state being accessed.
Source§type Guard<'l> = &'l <L as UnlockedAccessMarkerFor<T>>::Data
where
T: 'l
type Guard<'l> = &'l <L as UnlockedAccessMarkerFor<T>>::Data where T: 'l
A guard providing read access to the data.
Source§fn access(&self) -> <T as UnlockedAccess<L>>::Guard<'_>
fn access(&self) -> <T as UnlockedAccess<L>>::Guard<'_>
How to access the state.