Struct static_init::lazy::UnSyncLazy
source · pub struct UnSyncLazy<T, G = fn() -> T> { /* private fields */ }
Expand description
A version of Lazy whose reference can not be passed to other thread
Implementations§
source§impl<T, G> UnSyncLazy<T, G>
impl<T, G> UnSyncLazy<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 building any thing else than a thread local object or a static will 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 information
§Safety
This function may be unsafe if building any thing else than a thread local object or a static will be the cause of undefined behavior
source§impl<T, G> UnSyncLazy<T, G>where
G: Generator<T>,
impl<T, G> UnSyncLazy<T, G>where
G: Generator<T>,
sourcepub fn get(this: &Self) -> &T
pub fn get(this: &Self) -> &T
Initialize if necessary then return a reference to the target.
§Panics
Panic if previous attempt to initialize has panicked and the lazy policy does not tolorate further initialization attempt or if initialization panic.
sourcepub fn try_get(this: &Self) -> Result<&T, AccessError>
pub fn try_get(this: &Self) -> Result<&T, AccessError>
Return a reference to the target if initialized otherwise return an error.
sourcepub fn get_mut(this: &mut Self) -> &mut T
pub fn get_mut(this: &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(this: &mut Self) -> Result<&mut T, AccessError>
pub fn try_get_mut(this: &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