Re-implement Tag metaprogramming utility

This commit is contained in:
kayomn 2023-04-23 13:40:49 +01:00
parent a7605c6ffa
commit d1110d8683
1 changed files with 8 additions and 0 deletions

View File

@ -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,
};