Aleksey Kladov 63ea1029b8 Initial
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00
2018-08-02 03:12:28 +03:00

once_cell

Build Status Crates.io API reference

A macroless alternative to lazy_static. If you like this, you might also like lazycell

fn hashmap() -> &'static HashMap<u32, &'static str> {
    static INSTANCE: OnceCell<HashMap<u32, &'static str>> = OnceCell::INIT;
    INSTANCE.get_or_init(|| {
        let mut m = HashMap::new();
        m.insert(0, "foo");
        m.insert(1, "bar");
        m.insert(2, "baz");
        m
    })
}

If you want slightly sweeter syntax, we have macros as well!

static HASHMAP: Lazy<HashMap<u32, &'static str>> = sync_lazy! {
    let mut m = HashMap::new();
    m.insert(0, "foo");
    m.insert(1, "bar");
    m.insert(2, "baz");
    m
};
S
Description
提供一种在不使用互斥锁的情况下实现只初始化一次的单元格类型。 | A Rust library that provides a cell that can only be written to once.
Readme 1.7 MiB
Languages
Rust 100%