Struct static_init::Lazy
source · [−]pub struct Lazy<T, G = fn() -> T> { /* private fields */ }
Expand description
A type that initialize itself only once on the first access
Implementations
sourceimpl<T, G> Lazy<T, G>
impl<T, G> Lazy<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
sourceimpl<T, G> Lazy<T, G> where
G: Generator<T>,
impl<T, G> Lazy<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
Trait Implementations
sourceimpl<'a, T, G> LazyAccess for &'a Lazy<T, G> where
G: Generator<T>,
impl<'a, T, G> LazyAccess for &'a Lazy<T, G> where
G: Generator<T>,
Auto Trait Implementations
impl<T, G> RefUnwindSafe for Lazy<T, G> where
G: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, G> Send for Lazy<T, G> where
G: Send + Sync,
T: Send,
impl<T, G> Sync for Lazy<T, G> where
G: Sync,
T: Sync,
impl<T, G> Unpin for Lazy<T, G> where
G: Unpin,
T: Unpin,
impl<T, G> UnwindSafe for Lazy<T, G> where
G: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more