Struct static_init::UnSyncLockedLazy

source ·
pub struct UnSyncLockedLazy<T, G = fn() -> T> { /* private fields */ }
Expand description

A RefCell that initializes its content on the first access

Implementations§

source§

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

source

pub fn new(g: G) -> Self

source§

impl<T, G: Generator<T>> UnSyncLockedLazy<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 UnSyncLockedLazy<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 UnSyncLockedLazy<T, fn() -> T>

source§

fn default() -> Self

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

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

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T, G> Phased for UnSyncLockedLazy<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 UnSyncLockedLazy<T, G>

§

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

§

impl<T, G = fn() -> T> !Send for UnSyncLockedLazy<T, G>

§

impl<T, G = fn() -> T> !Sync for UnSyncLockedLazy<T, G>

§

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

§

impl<T, G> UnwindSafe for UnSyncLockedLazy<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.