What's the right way to do an enum subset?

There’s another method described here: Tagged Union Subsets with Comptime in Zig – Mitchell Hashimoto

Basically, make a fn isSupported(os: std.Target.Os.Tag) bool then build a custom SupportedOs type at comptime, along with helpers to convert back-and-forth between the two types.

It seems a bit nicer to me, though its hard to say why. For one, your ‘SupportedOS contains field not present in Os.Tag’ error message wouldn’t be necessary anymore, because it’d be impossible to get into that situation. I also like his use of null instead of .other.

2 Likes