cuprate icon indicating copy to clipboard operation
cuprate copied to clipboard

Usage of `LazyLock` over `OnceLock` + `fn`

Open hinto-janai opened this issue 7 months ago • 0 comments

What

Rust 1.80 stablized LazyLock.

This can replace any std::sync::OnceLock + fn usage.

Where

Any place using OnceLock + fn for LazyLock behavior, e.g.:

https://github.com/Cuprate/cuprate/blob/929d19c4508a84d886ece03009a6fcdc5edea5c2/helper/src/fs.rs#L86-L90

How

Replace OnceLock + fn with:

static _: LazyLock<T> = LazyLock::new(|| {
    /* old OnceLock::get_or_init function */
});

hinto-janai avatar Jul 25 '24 20:07 hinto-janai