#Switch on strings?
1 messages · Page 1 of 1 (latest)
suggestion: use std.meta.stringToEnum, where you use an enum with names of all the string cases you'd want to handle
const Case = enum {
fizz,
buzz,
@"fizz buzz",
};
const case = try std.meta.stringToEnum(Case, str);
switch (case) {
.fizz => {},
.buzz => {},
.@"fizz buzz" => {},
}
it uses std.ComptimeStringMap under the hood
thats pretty dope
I almost never use the meta package, but this case is too good to ignore