Skip to main content

LazyInit

Struct LazyInit 

Source
pub struct LazyInit<T, Check: Policy = BasicCheck> { /* private fields */ }
Expand description

A cell providing explicit, one-time initialization for a static value of type T.

LazyInit allows storing types in static memory that require runtime initialization. Accesses are validated according to the specified Policy strategy.

Implementations§

Source§

impl<T, Check: Policy> LazyInit<T, Check>

Source

pub const fn uninit() -> Self

Creates an uninitialized instance.

Source

pub unsafe fn init(&'static self, value: T)

Moves the given value into the wrapped storage.

§Safety

The caller must ensure that initialization is serialized with respect to any other access to this instance (i.e., that init does not race with any concurrent reads or other initialization calls).

§Panics

Panics if the instance has already been initialized or is currently initializing.

Source

pub unsafe fn init_pin<E>( self: Pin<&'static Self>, init: impl PinInit<T, E>, ) -> Result<(), E>

Explicitly constructs the wrapped value in-place using a PinInit initializer.

§Safety

The caller must ensure that initialization is serialized with respect to any other access to this instance (i.e., that init_pin does not race with any concurrent reads or other initialization calls).

§Panics

Panics if the instance has already been initialized or is currently initializing.

Source

pub const unsafe fn get_unchecked(&self) -> &T

Returns a reference to the wrapped value without checking initialization state.

§Safety

The caller must ensure that the instance has indeed been initialized.

Source§

impl<T, Check: CheckedPolicy> LazyInit<T, Check>

Source

pub fn get(&self) -> &T

Returns a reference to the wrapped value.

Asserts that initialization has already occurred.

§Panics

Panics if the instance has not been initialized.

Trait Implementations§

Source§

impl<T, Check: CheckedPolicy> Deref for LazyInit<T, Check>

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T: Send, Check: Policy> Send for LazyInit<T, Check>
where Check::State: Send,

Source§

impl<T: Sync, Check: Policy> Sync for LazyInit<T, Check>

Auto Trait Implementations§

§

impl<T, Check = BasicCheck> !Freeze for LazyInit<T, Check>

§

impl<T, Check = BasicCheck> !RefUnwindSafe for LazyInit<T, Check>

§

impl<T, Check> Unpin for LazyInit<T, Check>
where <Check as Policy>::State: Unpin, Check: Unpin, T: Unpin,

§

impl<T, Check> UnsafeUnpin for LazyInit<T, Check>
where <Check as Policy>::State: UnsafeUnpin, T: UnsafeUnpin,

§

impl<T, Check> UnwindSafe for LazyInit<T, Check>
where <Check as Policy>::State: UnwindSafe, Check: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Init<T> for T

Source§

unsafe fn __init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn chain<F>(self, f: F) -> ChainInit<Self, F, T, E>
where F: FnOnce(&mut T) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

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

§

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> PinInit<T> for T

Source§

unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), !>

Initializes slot. Read more
Source§

fn pin_chain<F>(self, f: F) -> ChainPinInit<Self, F, T, E>
where F: FnOnce(Pin<&mut T>) -> Result<(), E>,

First initializes the value using self then calls the function f with the initialized value. Read more
§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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.
§

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

Performs the conversion.