Is there a way to extend enums with more values?

On the topic of repeated enum values, I believe it is not allowed to have “field aliases”. There’s a whole big long debate in a related github issue:

enums should disallow multiple enumerations with the same value · Issue #2115 · ziglang/zig · GitHub

For merging two enums, it should be possible to do some comptime magic with std.meta.fields() to create a new enum which contains all the fields from any number of enums. Keep in mind that you’ll very likely get a compiler error if any of the values are the same. Creating enums at comptime looks like a good bet, although I don’t know how recent it is.

3 Likes