once_cell

Build Status Crates.io API reference

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

rust 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!

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