I was trying to make a map of strings to Zig enums and I found two ways.
One:
var BUILTINS = .{
.{ .name = "SELECT", .kind = Token.Kind.select_keyword },
.{ .name = "SELECT", .kind = Token.Kind.select_keyword },
... more stuff ...
};
But this I can only seem to iterate on with for (BUILTINS) |builtin| {...} as a comptime thing.
Then I had this other version
var BUILTINS = block: {
var builtins: [13]Builtin = undefined;
builtins[0] = .{ .name = "SELECT", .kind = Token.Kind.select_keyword };
builtins[1] = .{ .name = "CREATE", .kind = Token.Kind.create_keyword };
... more stuff ...
break :block builtins;
};
This second version is not restricted to comptime. But it's more convoluted to type.
Is there a version of the former one where I construct a literal array of anonymous structs but that isn't limited to comptime looping?
Thanks!