Struct static_init::lazy::locked_lazy::LockedLazy
source · pub struct LockedLazy<T, G = fn() -> T> { /* private fields */ }
Expand description
A mutable locked lazy that initialize its content on the first lock
Implementations§
source§impl<T, G> LockedLazy<T, G>where
G: Generator<T>,
impl<T, G> LockedLazy<T, G>where
G: Generator<T>,
source§impl<T, G> LockedLazy<T, G>where
G: Generator<T>,
impl<T, G> LockedLazy<T, G>where
G: Generator<T>,
sourcepub fn read(&self) -> ReadGuard<'_, T>
pub fn read(&self) -> ReadGuard<'_, T>
Initialize if necessary and returns a read lock
§Panic
Panics if initialization panics or if initialization has panicked in a previous attempt to initialize.
sourcepub fn fast_read(&self) -> Option<ReadGuard<'_, T>>
pub fn fast_read(&self) -> Option<ReadGuard<'_, T>>
Initialize if necessary and returns some read lock if the lazy is not
already write locked. If the lazy is already write locked it returns None
§Panic
If locks succeeds, panics if initialization panics or if initialization has panicked in a previous attempt to initialize.
sourcepub fn try_read(&self) -> Result<ReadGuard<'_, T>, AccessError>
pub fn try_read(&self) -> Result<ReadGuard<'_, T>, AccessError>
Get a read lock if the lazy is initialized or an AccessError
sourcepub fn fast_try_read(&self) -> Option<Result<ReadGuard<'_, T>, AccessError>>
pub fn fast_try_read(&self) -> Option<Result<ReadGuard<'_, T>, AccessError>>
if the lazy is not already write locked: get a read lock if the lazy is initialized or an AccessError.
Otherwise returns None
sourcepub fn write(&self) -> WriteGuard<'_, T>
pub fn write(&self) -> WriteGuard<'_, T>
Initialize if necessary and returns a write lock
§Panic
Panics if initialization panics or if initialization has panicked in a previous attempt to initialize.
sourcepub fn fast_write(&self) -> Option<WriteGuard<'_, T>>
pub fn fast_write(&self) -> Option<WriteGuard<'_, T>>
Initialize if necessary and returns some write lock if the lazy is not
already write locked. If the lazy is already read or write locked it returns None
§Panic
If locks succeeds, panics if initialization panics or if initialization has panicked in a previous attempt to initialize.
sourcepub fn try_write(&self) -> Result<WriteGuard<'_, T>, AccessError>
pub fn try_write(&self) -> Result<WriteGuard<'_, T>, AccessError>
Get a read lock if the lazy is initialized or an AccessError
sourcepub fn fast_try_write(&self) -> Option<Result<WriteGuard<'_, T>, AccessError>>
pub fn fast_try_write(&self) -> Option<Result<WriteGuard<'_, T>, AccessError>>
if the lazy is not already read or write locked: get a write lock if the lazy is initialized or an AccessError . Otherwise returns None
source§impl<T, G> LockedLazy<T, G>
impl<T, G> LockedLazy<T, G>
sourcepub const fn from_generator(f: G) -> Self
pub const fn from_generator(f: G) -> Self
Build a new static object.
§Safety
This function may be unsafe if build this object as anything else than a static or a thread local static would be the cause of undefined behavior
sourcepub const fn from_generator_with_info(f: G, info: StaticInfo) -> Self
pub const fn from_generator_with_info(f: G, info: StaticInfo) -> Self
Build a new static object with debug informations.
§Safety
This function may be unsafe if build this object as anything else than a static or a thread local static would be the cause of undefined behavior
source§impl<T: Send, G: Generator<T>> LockedLazy<T, G>
impl<T: Send, G: Generator<T>> LockedLazy<T, G>
sourcepub fn get_mut(&mut self) -> &mut T
pub fn get_mut(&mut self) -> &mut T
Initialize and return a mutable reference to the target
This method is extremly efficient as it does not requires any form of locking when initializing
sourcepub fn try_get_mut(&mut self) -> Result<&mut T, AccessError>
pub fn try_get_mut(&mut self) -> Result<&mut T, AccessError>
Return a mutable reference to the target if initialized otherwise return an error.
This method is extremly efficient as it does not requires any form of locking when initializing