Struct maitake::sync::spin::once::Lazy

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

A cell which will be lazily initialized by the provided function the first time it is accessed.

This can be used as a safer alternative to static mut.

Implementations§

source§

impl<T, F> Lazy<T, F>

source

pub const fn new(initializer: F) -> Lazy<T, F>

Returns a new Lazy cell, initialized with the provided initializer function.

source

pub fn get_if_present(&self) -> Option<&T>

Returns the value of the lazy cell, if it has already been initialized. Otherwise, returns None.

source§

impl<T, F> Lazy<T, F>
where F: Fn() -> T,

source

pub fn get(&self) -> &T

Borrow the value, or initialize it if it has not yet been initialized.

source

pub fn get_mut(&mut self) -> &mut T

Borrow the value mutably, or initialize it if it has not yet been initialized.

source

pub fn init(&self)

Ensure that the cell has been initialized.

If the cell has yet to be initialized, this initializes it. If it is currently initializing, this spins until it has been fully initialized. Otherwise, this returns immediately.

Trait Implementations§

source§

impl<T, F> Debug for Lazy<T, F>
where T: Debug,

source§

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

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

impl<T, F> Deref for Lazy<T, F>
where F: Fn() -> T,

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &<Lazy<T, F> as Deref>::Target

Dereferences the value.
source§

impl<T, F> DerefMut for Lazy<T, F>
where F: Fn() -> T,

source§

fn deref_mut(&mut self) -> &mut <Lazy<T, F> as Deref>::Target

Mutably dereferences the value.
source§

impl<T, F> Send for Lazy<T, F>
where T: Send, F: Send,

source§

impl<T, F> Sync for Lazy<T, F>
where T: Sync, F: Sync,

Auto Trait Implementations§

§

impl<T, F = fn() -> T> !Freeze for Lazy<T, F>

§

impl<T, F = fn() -> T> !RefUnwindSafe for Lazy<T, F>

§

impl<T, F> Unpin for Lazy<T, F>
where F: Unpin, T: Unpin,

§

impl<T, F> UnwindSafe for Lazy<T, F>
where F: 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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more