Crates.io | lazy-st |
lib.rs | lazy-st |
version | 1.0.0 |
source | src |
created_at | 2020-07-09 09:06:23.136924 |
updated_at | 2024-03-13 18:13:49.336757 |
description | Single-threaded lazy evaluation |
homepage | |
repository | https://github.com/01mf02/lazy-st/ |
max_upload_size | |
id | 262798 |
size | 10,387 |
This crate provides single-threaded lazy evaluation for Rust.
It is an adaptation of the lazy crate,
removing support for multi-threaded operation,
adding support for no_std
environments, and
making it compatible with newer Rust versions.
To share lazy values between threads, please consider using the lazy-mt crate.
fn expensive() -> i32 {
println!("I am only evaluated once!"); 7
}
fn main() {
let a = lazy!(expensive());
// Thunks are just smart pointers!
assert_eq!(*a, 7); // "I am only evaluated once!" is printed here
let b = [*a, *a]; // Nothing is printed.
assert_eq!(b, [7, 7]);
}