Re-implement Tag metaprogramming utility
This commit is contained in:
parent
a7605c6ffa
commit
d1110d8683
|
@ -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{
|
pub const WriteError = error{
|
||||||
IoUnavailable,
|
IoUnavailable,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue