Type Function Tag [src]
Prototype
pub fn Tag(comptime T: type) type
Example
test Tag {
const E = enum(u8) {
C = 33,
D,
};
const U = union(E) {
C: u8,
D: u16,
};
try testing.expect(Tag(E) == u8);
try testing.expect(Tag(U) == E);
}
Source
pub fn Tag(comptime T: type) type {
return switch (@typeInfo(T)) {
.@"enum" => |info| info.tag_type,
.@"union" => |info| info.tag_type orelse @compileError(@typeName(T) ++ " has no tag type"),
else => @compileError("expected enum or union type, found '" ++ @typeName(T) ++ "'"),
};
}