From d1110d8683cf25806fb9c9c6ee15631f21e6ec8d Mon Sep 17 00:00:00 2001 From: kayomn Date: Sun, 23 Apr 2023 13:40:49 +0100 Subject: [PATCH] Re-implement Tag metaprogramming utility --- source/coral/io.zig | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/source/coral/io.zig b/source/coral/io.zig index 7961cfc..deba662 100755 --- a/source/coral/io.zig +++ b/source/coral/io.zig @@ -84,6 +84,14 @@ pub const Reader = struct { } }; +pub fn Tag(comptime Element: type) type { + return switch (@typeInfo(Element)) { + .Enum => |info| info.tag_type, + .Union => |info| info.tag_type orelse @compileError(@typeName(Element) ++ " has no tag type"), + else => @compileError("expected enum or union type, found '" ++ @typeName(Element) ++ "'"), + }; +} + pub const WriteError = error{ IoUnavailable, };