| ... | ... | @@ -105,6 +105,7 @@ test "std.meta.isTag for Tagged Unions" { |
| 105 | 105 | try testing.expect(!isTag(flt, "int")); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | /// Returns the variant of an enum type, `T`, which is named `str`, or `null` if no such variant exists. |
| 108 | 109 | pub fn stringToEnum(comptime T: type, str: []const u8) ?T { |
| 109 | 110 | // Using ComptimeStringMap here is more performant, but it will start to take too |
| 110 | 111 | // long to compile if the enum is large enough, due to the current limits of comptime |
| ... | ... | @@ -192,6 +193,7 @@ test "std.meta.alignment" { |
| 192 | 193 | try testing.expect(alignment(fn () align(128) void) == 128); |
| 193 | 194 | } |
| 194 | 195 | |
| 196 | /// Given a parameterized type (array, vector, pointer, optional), returns the "child type". |
| 195 | 197 | pub fn Child(comptime T: type) type { |
| 196 | 198 | return switch (@typeInfo(T)) { |
| 197 | 199 | .Array => |info| info.child, |
| ... | ... | @@ -210,7 +212,7 @@ test "std.meta.Child" { |
| 210 | 212 | try testing.expect(Child(Vector(2, u8)) == u8); |
| 211 | 213 | } |
| 212 | 214 | |
| 213 | | /// Given a "memory span" type, returns the "element type". |
| 215 | /// Given a "memory span" type (array, slice, vector, or pointer to such), returns the "element type". |
| 214 | 216 | pub fn Elem(comptime T: type) type { |
| 215 | 217 | switch (@typeInfo(T)) { |
| 216 | 218 | .Array => |info| return info.child, |
| ... | ... | @@ -505,7 +507,6 @@ test "std.meta.declarationInfo" { |
| 505 | 507 | try testing.expect(!info.is_pub); |
| 506 | 508 | } |
| 507 | 509 | } |
| 508 | | |
| 509 | 510 | pub fn fields(comptime T: type) switch (@typeInfo(T)) { |
| 510 | 511 | .Struct => []const Type.StructField, |
| 511 | 512 | .Union => []const Type.UnionField, |
| ... | ... | @@ -652,6 +653,7 @@ test "std.meta.tags" { |
| 652 | 653 | try testing.expectEqual(E2.A, e2_tags[0]); |
| 653 | 654 | } |
| 654 | 655 | |
| 656 | /// Returns an enum with a variant named after each field of `T`. |
| 655 | 657 | pub fn FieldEnum(comptime T: type) type { |
| 656 | 658 | const field_infos = fields(T); |
| 657 | 659 | |