编译Zig中的时间哈希图
以Rust库 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 how how how how这可以在Zig中完成吗?
我已经尝试了这一点,这对我来说是唯一有意义的事情:
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});
}
但是这是segfault。
甚至可以在Zig中这样做吗?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于Zig 0.13.0
具有Zig 0.13.0,因此以前已知的
std.comptimestringmap
在 /commit/8AF59D1F98266BD70B3AFB44D196BBD151CEDF22“ rel =“ nofollow noreferrer”>提交8af59d1std.staticstringmap
,现在活着在这里图书馆。直到Zig 0.12.1
似乎(感谢此 reddit post )这是在标准库
,可以通过
std使用。 CompTimestringMap
这似乎不支持任何动态插入。但是,由于没有
insert
方法,因此Since zig 0.13.0
With zig 0.13.0, the previously known
std.ComptimeStringMap
was renamed in commit 8af59d1 tostd.StaticStringMap
, and now lives here in the standard library.Until zig 0.12.1
It seems (thanks to this Reddit post) that this is implemented in the standard library
and can be used via
std.ComptimeStringMap
This however does not seem to support any dynamic insertion as there is no
insert
method.