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

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§

§

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

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

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

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

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

§

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

pub fn get(&self) -> &T

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

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

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

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§

§

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

§

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

Formats the value using the given formatter. Read more
§

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

§

type Target = T

The resulting type after dereferencing.
§

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

Dereferences the value.
§

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

§

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

Mutably dereferences the value.
§

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

§

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

Auto Trait Implementations§

§

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.

§

impl<T> Instrument for T

§

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

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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