Crate critical_once_cell

Source
Expand description

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!");
}

Structs§

CriticalLazy
A thread-safe value which is initialized on the first access.
CriticalOnceCell
A thread-safe cell which can be written to only once.