pub struct Lazy<T, F = fn() -> T> { /* private fields */ }
Expand description
A value which is initialized on the first access.
This type is thread-safe and can be used in statics.
§Example
In this example, Heatmap
does not have a const new
function so it
must be constructed using Lazy
.
#[metric]
static HEATMAP: Lazy<Heatmap> = Lazy::new(|| {
Heatmap::new(
100,
2,
Duration::<Nanoseconds<u64>>::from_secs(30),
Duration::<Nanoseconds<u64>>::from_secs(1),
)
});
Implementations§
Trait Implementations§
source§impl<T: Metric, F: Send + 'static> Metric for Lazy<T, F>
impl<T: Metric, F: Send + 'static> Metric for Lazy<T, F>
impl<T, F: Send> Sync for Lazy<T, F>
Auto Trait Implementations§
impl<T, F = fn() -> T> !Freeze for Lazy<T, F>
impl<T, F = fn() -> T> !RefUnwindSafe for Lazy<T, F>
impl<T, F> Send for Lazy<T, F>
impl<T, F> Unpin for Lazy<T, F>
impl<T, F> UnwindSafe for Lazy<T, F>where
T: UnwindSafe,
F: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more