Implementing switch on multiple enum values with comptime
Ziggit
Implementing switch on multiple enum values with comptime
That’s something I made today and I thought that some other people might want to use something like it. It works on enums, it doesn’t work on tagged unions when you want to capture. Example of using it: const EnumA = enum (u1) { Red, Black, }; const EnumB = enum(u1) { Up, Down, }; pub fn main() !void { const a: EnumA = .Red; const b: EnumB = .Down; const s = switch (match(.{a, b})) { .case(.{.Red, .Up}) => "red up", .case(.{.Red, .Down}) => "red do...
0 comments
No comments yet.