std: use FieldEnum from TrailerFlags

This commit is contained in:
daurnimator 2020-12-13 22:27:33 +11:00 committed by Andrew Kelley
parent 9c97a07f18
commit 4387e50d4f

View File

@ -21,20 +21,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
pub const Int = meta.Int(.unsigned, bit_count);
pub const bit_count = @typeInfo(Fields).Struct.fields.len;
pub const FieldEnum = blk: {
comptime var fields: [bit_count]TypeInfo.EnumField = undefined;
inline for (@typeInfo(Fields).Struct.fields) |struct_field, i|
fields[i] = .{ .name = struct_field.name, .value = i };
break :blk @Type(.{
.Enum = .{
.layout = .Auto,
.tag_type = std.math.IntFittingRange(0, bit_count - 1),
.fields = &fields,
.decls = &[_]TypeInfo.Declaration{},
.is_exhaustive = true,
},
});
};
pub const FieldEnum = std.meta.FieldEnum(Fields);
pub const InitStruct = blk: {
comptime var fields: [bit_count]TypeInfo.StructField = undefined;