Skip to main content

Lazy

Struct Lazy 

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

A value built by F on first access.

Built on OnceCell::get_or_init_racy: threads that reach an unbuilt Lazy at the same moment each run F, one result is kept and the others are dropped, and nobody waits for anybody. F therefore runs at least once and possibly more than once, so it is Fn and should be free of side effects that must not repeat.

use nuclei::sync::Lazy;

static TABLE: Lazy<Vec<u32>> = Lazy::new(|| (0..4).collect());
assert_eq!(TABLE.len(), 4);

Implementations§

Source§

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

Source

pub const fn new(init: F) -> Self

A Lazy that builds its value with init.

Source§

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

Source

pub fn force(this: &Self) -> &T

The value, building it if nobody has yet.

Trait Implementations§

Source§

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

Source§

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

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

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

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &T

Dereferences the value.

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 = fn() -> T> !UnwindSafe for Lazy<T, F>

§

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

§

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

§

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

§

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

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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

Source§

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

Source§

type Target = T

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

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

Source§

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

Source§

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.