const std = @import("std"); const meta = std.meta; /// Given a list of names, creates an enum type with those names as its fields. /// The underlying tag type is set to the smallest available integer for the length of the list. /// The underlying value for each field is set in the order they appear in the list. The enum is /// considered exhaustive. pub fn Enum(comptime enums: []const [:0]const u8) type { var fields: [enums.len]std.builtin.Type.EnumField = undefined; for (enums, 0..) |value, i| { fields[i] = .{ .name = value, .value = i }; } return @Type(.{ .@"enum" = .{ .tag_type = meta.Int(.unsigned, enums.len), .fields = &fields, .decls = &.{}, .is_exhaustive = true, } }); }