Struct static_init::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>

source

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

source

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

source

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.

source

pub fn try_get(this: &Self) -> Result<&T, AccessError>

Return a reference to the target if initialized otherwise return an error.

source

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

source

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

source

pub fn phase(this: &Self) -> Phase

Return the phase

source

pub fn init(this: &Self) -> Phase

Initialize the lazy if not yet initialized

§Panic

Panic if the generator panics

source§

impl<T, G> UnSyncLazy<T, Cell<Option<G>>>
where G: FnOnce() -> T,

source

pub fn new(g: G) -> Self

Trait Implementations§

source§

impl<T: Debug, G> Debug for UnSyncLazy<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 UnSyncLazy<T, fn() -> T>

source§

fn default() -> Self

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

impl<T, G> Deref for UnSyncLazy<T, G>
where G: Generator<T>,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T, G> DerefMut for UnSyncLazy<T, G>
where G: Generator<T>,

source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
source§

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

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<'a, T, G> LazyAccess for &'a UnSyncLazy<T, G>
where G: Generator<T>,

§

type Target = &'a T

source§

fn get(this: Self) -> &'a T

Initialize if necessary then return a reference to the target. Read more
source§

fn try_get(this: Self) -> Result<&'a T, AccessError>

Return a reference to the target if initialized otherwise return an error.
source§

fn phase(this: Self) -> Phase

The current phase of the static
source§

fn init(this: Self) -> Phase

Initialize the static if there were no previous attempt to initialize it.
source§

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

§

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

§

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

§

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

§

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

§

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