Deprecated: The each() function is deprecated. This message will be suppressed on further calls in /home/zhenxiangba/zhenxiangba.com/public_html/phproxy-improved-master/index.php on line 456
once_cell 0.0.1 - Docs.rs
[go: Go Back, main page]

once_cell 0.0.1

Lazy and lazy static values without macros
Documentation
once_cell-0.0.1 has been yanked.

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
};