Lazy

Struct Lazy 

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

A type for lazy initialization of e.g. global static variables, which provides the same functionality as the lazy_static! macro.

Implementations§

Source§

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

Source

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

Creates a new uninitialized Lazy with the given init closure.

§Examples

The init argument can be a simple function pointer or any FnOnce closure.

use conquer_once::Lazy;

static LAZY_1: Lazy<Vec<i32>> = Lazy::new(|| vec![1, 2, 3, 4, 5]);
static LAZY_2: Lazy<Vec<i32>> = Lazy::new(Vec::<i32>::new);
Source

pub fn is_initialized(lazy: &Self) -> bool

Returns true if the Lazy has been successfully initialized.

Source

pub fn is_poisoned(lazy: &Self) -> bool

Returns true if the Lazy has been poisoned.

Source§

impl<T, B, F> Lazy<T, B, F>
where B: Block, F: FnOnce() -> T,

Source

pub fn get_or_init(lazy: &Self) -> &T

Returns a reference to the already initialized inner value or initializes it first.

This has the same effect as using the Deref operator on a Lazy.

§Panics

This method panics if the init procedure specified during construction panics or if the Lazy is poisoned.

Trait Implementations§

Source§

impl<T, B, F> AsRef<T> for Lazy<T, B, F>
where B: Block, F: FnOnce() -> T,

Source§

fn as_ref(&self) -> &T

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T, B, F> Borrow<T> for Lazy<T, B, F>
where B: Block, F: FnOnce() -> T,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T, B, F> Debug for Lazy<T, B, F>
where T: Debug, B: Unblock, F: FnOnce() -> T,

Source§

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

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

impl<T, B, F> Deref for Lazy<T, B, F>
where B: Block, F: FnOnce() -> T,

Source§

type Target = T

The resulting type after dereferencing.
Source§

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

Dereferences the value.
Source§

impl<T, B, F> Display for Lazy<T, B, F>
where T: Display, B: Block, F: FnOnce() -> T,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T, B, F> UnwindSafe for Lazy<T, B, F>
where F: UnwindSafe, B: 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<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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.