Take for example the Rust library lazy_static's example:
use lazy_static::lazy_static;
use std::collections::HashMap;
lazy_static! {
static ref HASHMAP: HashMap<u32, &'static str> = {
let mut m = HashMap::new();
m.insert(0, "foo");
m.insert(1, "bar");
m.insert(2, "baz");
m
};
static ref COUNT: usize = HASHMAP.len();
static ref NUMBER: u32 = times_two(21);
}
How might this be done in Zig?
I have tried this which is the only thing that makes sense to me:
const std = @import("std");
pub fn main() void {
comptime var h = std.StringHashMap(i32).init(std.testing.allocator);
h.put("hi", 5) catch {};
std.debug.print("{}", .{h});
}
but this segfaults.
Is it even possible to do this in Zig?