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>,

source

pub fn phase(&self) -> Phase

Returns the current phase and synchronize with the end of the transition to the returned phase.

source§

impl<T, G> LockedLazy<T, G>
where G: Generator<T>,

source

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.

source

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.

source

pub fn try_read(&self) -> Result<ReadGuard<'_, T>, AccessError>

Get a read lock if the lazy is initialized or an AccessError

source

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

source

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.

source

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.

source

pub fn try_write(&self) -> Result<WriteGuard<'_, T>, AccessError>

Get a read lock if the lazy is initialized or an AccessError

source

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

pub fn init(&self)

Initialize the lazy if no previous attempt to initialized it where performed

source§

impl<T, G> LockedLazy<T, G>

source

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

source

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, G> LockedLazy<T, Cell<Option<G>>>
where G: FnOnce() -> T,

source

pub fn new(g: G) -> Self

source§

impl<T: Send, G: Generator<T>> LockedLazy<T, G>

source

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

source

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

Trait Implementations§

source§

impl<T: Debug, G> Debug for LockedLazy<T, G>
where G: Generator<T>,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Default> Default for LockedLazy<T, fn() -> T>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<T, G> Drop for LockedLazy<T, G>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T, G> Phased for LockedLazy<T, G>
where G: Generator<T>,

source§

fn phase(this: &Self) -> Phase

return the current phase

Auto Trait Implementations§

§

impl<T, G = fn() -> T> !Freeze for LockedLazy<T, G>

§

impl<T, G = fn() -> T> !RefUnwindSafe for LockedLazy<T, G>

§

impl<T, G> Send for LockedLazy<T, G>
where G: Send + Sync, T: Send,

§

impl<T, G> Sync for LockedLazy<T, G>
where G: Sync, T: Send,

§

impl<T, G> Unpin for LockedLazy<T, G>
where G: Unpin, T: Unpin,

§

impl<T, G> UnwindSafe for LockedLazy<T, G>
where G: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.