matklad / once_cell

Rust library for single assignment cells and lazy statics without macros
Apache License 2.0
1.87k stars 109 forks source link

once proc-macro #10

Closed matklad closed 5 years ago

matklad commented 5 years ago

We should add proc-macro on top of once-cell with the following API

#[once_cell::once]
fn global_map() -> &'static HashMap<u32, &'static str> {
        let mut m = HashMap::new();
        m.insert(0, "foo");
        m.insert(1, "bar");
        m
}

This imo is more transparent than lazy_static's API. Note that, on the call site, there will be a function call instead of Deref, which is less ergonomic, but more obvious: you see where costly initialization might take place.

matklad commented 5 years ago

This now is more-or-less achieavable without macros with Lazy