lazy-st

Crates.iolazy-st
lib.rslazy-st
version1.0.0
sourcesrc
created_at2020-07-09 09:06:23.136924
updated_at2024-03-13 18:13:49.336757
descriptionSingle-threaded lazy evaluation
homepage
repositoryhttps://github.com/01mf02/lazy-st/
max_upload_size
id262798
size10,387
Michael Färber (01mf02)

documentation

README

lazy-st

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.

Example

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]);
}
Commit count: 15

cargo fmt