diff options
| author | Tadeo Kondrak <me@tadeo.ca> | 2021-01-11 10:56:18 -0700 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2021-01-30 13:19:52 +0200 |
| commit | 68ec54f386d387c5dd3f9dc4f0b5e14be6ae10a6 (patch) | |
| tree | 85e45ff4284fc836c299b88e0bf2eca61140bd4b /lib/std/meta.zig | |
| parent | 290efc074797e893678154efac61f94a38f6bfc1 (diff) | |
| download | zig-68ec54f386d387c5dd3f9dc4f0b5e14be6ae10a6.tar.gz zig-68ec54f386d387c5dd3f9dc4f0b5e14be6ae10a6.zip | |
std.meta: rename TagType to Tag
Diffstat (limited to 'lib/std/meta.zig')
| -rw-r--r-- | lib/std/meta.zig | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig index b6107e6fa5..027b9508e2 100644 --- a/lib/std/meta.zig +++ b/lib/std/meta.zig @@ -600,15 +600,18 @@ test "std.meta.FieldEnum" { expectEqualEnum(enum { a, b, c }, FieldEnum(union { a: u8, b: void, c: f32 })); } -pub fn TagType(comptime T: type) type { +// Deprecated: use Tag +pub const TagType = Tag; + +pub fn Tag(comptime T: type) type { return switch (@typeInfo(T)) { .Enum => |info| info.tag_type, - .Union => |info| if (info.tag_type) |Tag| Tag else null, + .Union => |info| if (info.tag_type) |TheTag| TheTag else null, else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"), }; } -test "std.meta.TagType" { +test "std.meta.Tag" { const E = enum(u8) { C = 33, D, @@ -618,8 +621,8 @@ test "std.meta.TagType" { D: u16, }; - testing.expect(TagType(E) == u8); - testing.expect(TagType(U) == E); + testing.expect(Tag(E) == u8); + testing.expect(Tag(U) == E); } ///Returns the active tag of a tagged union @@ -694,13 +697,13 @@ pub fn eql(a: anytype, b: @TypeOf(a)) bool { } }, .Union => |info| { - if (info.tag_type) |Tag| { + if (info.tag_type) |UnionTag| { const tag_a = activeTag(a); const tag_b = activeTag(b); if (tag_a != tag_b) return false; inline for (info.fields) |field_info| { - if (@field(Tag, field_info.name) == tag_a) { + if (@field(UnionTag, field_info.name) == tag_a) { return eql(@field(a, field_info.name), @field(b, field_info.name)); } } @@ -822,9 +825,9 @@ test "intToEnum with error return" { pub const IntToEnumError = error{InvalidEnumTag}; -pub fn intToEnum(comptime Tag: type, tag_int: anytype) IntToEnumError!Tag { - inline for (@typeInfo(Tag).Enum.fields) |f| { - const this_tag_value = @field(Tag, f.name); +pub fn intToEnum(comptime EnumTag: type, tag_int: anytype) IntToEnumError!EnumTag { + inline for (@typeInfo(EnumTag).Enum.fields) |f| { + const this_tag_value = @field(EnumTag, f.name); if (tag_int == @enumToInt(this_tag_value)) { return this_tag_value; } |
