Struct diem_sdk::crypto::_once_cell::unsync::Lazy [−]
pub struct Lazy<T, F = fn() -> T> { /* fields omitted */ }
Expand description
A value which is initialized on the first access.
Example
use once_cell::unsync::Lazy;
let lazy: Lazy<i32> = Lazy::new(|| {
println!("initializing");
92
});
println!("ready");
println!("{}", *lazy);
println!("{}", *lazy);
// Prints:
// ready
// initializing
// 92
// 92
Implementations
impl<T, F> Lazy<T, F>
impl<T, F> Lazy<T, F>
Creates a new lazy value with the given initializing function.
Example
use once_cell::unsync::Lazy;
let hello = "Hello, World!".to_string();
let lazy = Lazy::new(|| hello.to_uppercase());
assert_eq!(&*lazy, "HELLO, WORLD!");
pub fn into_value(this: Lazy<T, F>) -> Result<T, F>
pub fn into_value(this: Lazy<T, F>) -> Result<T, F>
Consumes this Lazy
returning the stored value.
Returns Ok(value)
if Lazy
is initialized and Err(f)
otherwise.
Trait Implementations
Auto Trait Implementations
impl<T, F> UnwindSafe for Lazy<T, F> where
F: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more