[−][src]Struct std::lazy::Lazy

pub struct Lazy<T, F = fn() -> T> { /* fields omitted */ }
🔬 This is a nightly-only experimental API. (once_cell #74465)

A value which is initialized on the first access.

Examples

#![feature(once_cell)]

use std::lazy::Lazy;

let lazy: Lazy<i32> = Lazy::new(|| {
    println!("initializing");
    92
});
println!("ready");
println!("{}", *lazy);
println!("{}", *lazy);

// Prints:
//   ready
//   initializing
//   92
//   92
Run

Auto Trait Implementations

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

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

impl<T, F = fn() -> T> !Sync 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

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.