critical-once-cell

Crates.iocritical-once-cell
lib.rscritical-once-cell
version0.1.0
sourcesrc
created_at2022-04-20 12:30:05.307763
updated_at2022-04-20 12:30:05.307763
descriptionThread-safe OnceCell and Lazy backed by critical section
homepage
repositoryhttps://github.com/rustne-kretser/critical-once-cell
max_upload_size
id570950
size12,893
Eivind Alexander Bergem (eivindbergem)

documentation

README

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.1.0"

License

MPL-2.0

Commit count: 2

cargo fmt