[][src]Type Definition conquer_once::OnceCell

type OnceCell<T> = OnceCell<T, ParkThread>;

An interior mutability cell type which allows synchronized one-time initialization and read-only access exclusively after initialization.

For the API of this type alias, see the generic OnceCell type.

Examples

use conquer_once::OnceCell;

#[derive(Copy, Clone)]
struct Configuration {
    mode: i32,
    threshold: u64,
    msg: &'static str,
}

static CONFIG: OnceCell<Configuration> = OnceCell::new();

// producer thread
CONFIG.init_once(|| Configuration {
    mode: 2,
    threshold: 128,
    msg: "..."
});

// consumer thread
let res = CONFIG.get().copied();
if let Some(config) = res {
    assert_eq!(config.mode, 2);
    assert_eq!(config.threshold, 128);
}