2 unstable releases

0.2.0 Feb 13, 2025
0.1.0 Apr 20, 2022

#364 in Concurrency

Download history 1/week @ 2024-10-29 1/week @ 2024-11-05 132/week @ 2025-02-11

132 downloads per month

MPL-2.0 license

15KB
219 lines

Pipeline Crates.io API reference

critical-once-cell

Drop-in replacements for core::lazy::OnceCell and core::lazy::Lazy, backed by critical_section.

Examples

CriticalOnceCell

use critical_once_cell::CriticalOnceCell;

static CELL: CriticalOnceCell<String> = CriticalOnceCell::new();

fn main() {
    CELL.set("Hello, World!".to_owned()).unwrap();

    assert_eq!(*CELL.get().unwrap(), "Hello, World!");
}

CriticalLazy

use critical_once_cell::CriticalLazy;

static LAZY: CriticalLazy<String> = CriticalLazy::new(|| "Hello, World!".to_owned());

fn main() {
    assert_eq!(*LAZY, "Hello, World!");
}

For more details, see docs.

Usage

Add this to your Cargo.toml:

[dependencies]
critical-once-cell = "0.2.0"

License

MPL-2.0

Dependencies

~34KB