aboutsummaryrefslogtreecommitdiff
path: root/lib/std/meta.zig
diff options
context:
space:
mode:
authorMeghan <hello@nektro.net>2023-07-10 11:35:36 -0700
committerGitHub <noreply@github.com>2023-07-10 14:35:36 -0400
commit3d5751b57922a2ccadde70b63fac91665a74cae7 (patch)
tree27c7f644e992c691c1abd70ab7edf092c587697f /lib/std/meta.zig
parentcd0594e4a6a8449e3c1c9da5130a4252869e627c (diff)
downloadzig-3d5751b57922a2ccadde70b63fac91665a74cae7.tar.gz
zig-3d5751b57922a2ccadde70b63fac91665a74cae7.zip
std.meta: remove isTag (#15584)
This is not used by Zig itself anywhere and not using the function is more idiomatic.
Diffstat (limited to 'lib/std/meta.zig')
-rw-r--r--lib/std/meta.zig48
1 files changed, 1 insertions, 47 deletions
diff --git a/lib/std/meta.zig b/lib/std/meta.zig
index 8fe0aee9fb..6c0f1a47a4 100644
--- a/lib/std/meta.zig
+++ b/lib/std/meta.zig
@@ -16,53 +16,7 @@ test {
pub const tagName = @compileError("deprecated; use @tagName or @errorName directly");
-/// Given an enum or tagged union, returns true if the comptime-supplied
-/// string matches the name of the tag value. This match process should
-/// be, at runtime, O(1) in the number of tags available to the enum or
-/// union, and it should also be O(1) in the length of the comptime tag
-/// names.
-pub fn isTag(tagged_value: anytype, comptime tag_name: []const u8) bool {
- const T = @TypeOf(tagged_value);
- const type_info = @typeInfo(T);
- const type_name = @typeName(T);
-
- // select the Enum type out of the type (in the case of the tagged union, extract it)
- const E = if (.Enum == type_info) T else if (.Union == type_info) (type_info.Union.tag_type orelse {
- @compileError("attempted to use isTag on the untagged union " ++ type_name);
- }) else {
- @compileError("attempted to use isTag on a value of type (" ++ type_name ++ ") that isn't an enum or a union.");
- };
-
- return tagged_value == @field(E, tag_name);
-}
-
-test "std.meta.isTag for Enums" {
- const EnumType = enum { a, b };
- var a_type: EnumType = .a;
- var b_type: EnumType = .b;
-
- try testing.expect(isTag(a_type, "a"));
- try testing.expect(!isTag(a_type, "b"));
- try testing.expect(isTag(b_type, "b"));
- try testing.expect(!isTag(b_type, "a"));
-}
-
-test "std.meta.isTag for Tagged Unions" {
- const TaggedUnionEnum = enum { int, flt };
-
- const TaggedUnionType = union(TaggedUnionEnum) {
- int: i64,
- flt: f64,
- };
-
- var int = TaggedUnionType{ .int = 1234 };
- var flt = TaggedUnionType{ .flt = 12.34 };
-
- try testing.expect(isTag(int, "int"));
- try testing.expect(!isTag(int, "flt"));
- try testing.expect(isTag(flt, "flt"));
- try testing.expect(!isTag(flt, "int"));
-}
+pub const isTag = @compileError("deprecated; use 'tagged_value == @field(E, tag_name)' directly");
/// Returns the variant of an enum type, `T`, which is named `str`, or `null` if no such variant exists.
pub fn stringToEnum(comptime T: type, str: []const u8) ?T {