Type Alias spin::Lazy

source ·
pub type Lazy<T, F = fn() -> T> = Lazy<T, F>;
Expand description

A value which is initialized on the first access. See lazy::Lazy for documentation.

A note for advanced users: this alias exists to avoid subtle type inference errors due to the default relax strategy type parameter. If you need a non-default relax strategy, use the fully-qualified path.

Aliased Type§

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

Implementations§

source§

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

source

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

Creates a new lazy value with the given initializing function.

source

pub fn as_mut_ptr(&self) -> *mut T

Retrieves a mutable pointer to the inner data.

This is especially useful when interfacing with low level code or FFI where the caller explicitly knows that it has exclusive access to the inner data. Note that reading from this pointer is UB until initialized or directly written to.

source§

impl<T, F: FnOnce() -> T, R: RelaxStrategy> Lazy<T, F, R>

source

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

Forces the evaluation of this lazy value and returns a reference to result. This is equivalent to the Deref impl, but is explicit.

Examples
use spin::Lazy;

let lazy = Lazy::new(|| 92);

assert_eq!(Lazy::force(&lazy), &92);
assert_eq!(&*lazy, &92);

Trait Implementations§

source§

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

source§

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

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

impl<T: Default, R> Default for Lazy<T, fn() -> T, R>

source§

fn default() -> Self

Creates a new lazy value using Default as the initializing function.

source§

impl<T, F: FnOnce() -> T, R: RelaxStrategy> Deref for Lazy<T, F, R>

§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &T

Dereferences the value.
source§

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