Module std.lazy
A single-owner value initialized on first demand.
Construct with lazy.new(|| load_config()), then call value() through a
var binding. Each read returns an independent ordinary value. The result
type must support Clone; the initializer may suspend and is consumed once.
An ordinary Result.Err is cached just like any other value.
A fault or cancellation during initialization leaves the lazy value terminal. A later demand fails instead of retrying. Recursive demand also fails.
Contents
Functions
Function new
pub fn new<T: Clone>(consume initialize: fn() -> T) -> Lazy<T>
Retain an initializer without running it.
Types
Struct Lazy
A single-owner deferred value. Captured initializer resources and the cached value are released automatically when this owner leaves scope.
Fields
Inherent methods
impl<T: Clone> Lazy<T>
pub fn value(var self) -> T
Initialize once, then return an independent copy of the cached value. A recursive demand or a demand after failed initialization faults.
impl<T> Lazy<T>
pub fn close(consume self)
Release this lazy value early without running an unused initializer.