| ... | ... | @@ -22,16 +22,14 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 22 | 22 | pub const bit_count = @typeInfo(Fields).Struct.fields.len; |
| 23 | 23 | |
| 24 | 24 | pub const FieldEnum = blk: { |
| 25 | | comptime var fields: []const TypeInfo.EnumField = &[_]TypeInfo.EnumField{}; |
| 26 | | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { |
| 27 | | const field = TypeInfo.EnumField{ .name = struct_field.name, .value = i }; |
| 28 | | fields = fields ++ [_]TypeInfo.EnumField{field}; |
| 29 | | } |
| 25 | comptime var fields: [bit_count]TypeInfo.EnumField = undefined; |
| 26 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| |
| 27 | fields[i] = .{ .name = struct_field.name, .value = i }; |
| 30 | 28 | break :blk @Type(.{ |
| 31 | 29 | .Enum = .{ |
| 32 | 30 | .layout = .Auto, |
| 33 | 31 | .tag_type = std.math.IntFittingRange(0, bit_count - 1), |
| 34 | | .fields = fields, |
| 32 | .fields = &fields, |
| 35 | 33 | .decls = &[_]TypeInfo.Declaration{}, |
| 36 | 34 | .is_exhaustive = true, |
| 37 | 35 | }, |
| ... | ... | @@ -39,19 +37,21 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 39 | 37 | }; |
| 40 | 38 | |
| 41 | 39 | pub const InitStruct = blk: { |
| 42 | | comptime var fields: []const TypeInfo.StructField = &[_]TypeInfo.StructField{}; |
| 40 | comptime var fields: [bit_count]TypeInfo.StructField = undefined; |
| 43 | 41 | inline for (@typeInfo(Fields).Struct.fields) |struct_field, i| { |
| 44 | | const field = TypeInfo.StructField{ |
| 42 | fields[i] = TypeInfo.StructField{ |
| 45 | 43 | .name = struct_field.name, |
| 46 | 44 | .field_type = ?struct_field.field_type, |
| 47 | | .default_value = @as(??struct_field.field_type, @as(?struct_field.field_type, null)), |
| 45 | .default_value = @as( |
| 46 | ??struct_field.field_type, |
| 47 | @as(?struct_field.field_type, null), |
| 48 | ), |
| 48 | 49 | }; |
| 49 | | fields = fields ++ [_]TypeInfo.StructField{field}; |
| 50 | 50 | } |
| 51 | 51 | break :blk @Type(.{ |
| 52 | 52 | .Struct = .{ |
| 53 | 53 | .layout = .Auto, |
| 54 | | .fields = fields, |
| 54 | .fields = &fields, |
| 55 | 55 | .decls = &[_]TypeInfo.Declaration{}, |
| 56 | 56 | .is_tuple = false, |
| 57 | 57 | }, |
| ... | ... | @@ -77,7 +77,6 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /// `fields` is a struct with each field set to an optional value. |
| 80 | | /// Missing fields are assumed to be `null`. |
| 81 | 80 | /// Only the non-null bits are observed and are used to set the flag bits. |
| 82 | 81 | pub fn init(fields: InitStruct) Self { |
| 83 | 82 | var self: Self = .{ .bits = 0 }; |
| ... | ... | @@ -89,7 +88,6 @@ pub fn TrailerFlags(comptime Fields: type) type { |
| 89 | 88 | } |
| 90 | 89 | |
| 91 | 90 | /// `fields` is a struct with each field set to an optional value (same as `init`). |
| 92 | | /// Missing fields are assumed to be `null`. |
| 93 | 91 | pub fn setMany(self: Self, p: [*]align(@alignOf(Fields)) u8, fields: InitStruct) void { |
| 94 | 92 | inline for (@typeInfo(Fields).Struct.fields) |field, i| { |
| 95 | 93 | if (@field(fields, field.name)) |value| |