Function takeEnumNonexhaustive [src]
Reads an integer with the same size as the given nonexhaustive enum's tag type.
Asserts the buffer was initialized with a capacity at least @sizeOf(Enum).
Prototype
pub fn takeEnumNonexhaustive(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Error!Enum
Parameters
r: *Reader
Enum: type
endian: std.builtin.Endian
Possible Errors
See the Reader
implementation for detailed diagnostics.
Source
pub fn takeEnumNonexhaustive(r: *Reader, comptime Enum: type, endian: std.builtin.Endian) Error!Enum {
const info = @typeInfo(Enum).@"enum";
comptime assert(!info.is_exhaustive);
comptime assert(@bitSizeOf(info.tag_type) == @sizeOf(info.tag_type) * 8);
return takeEnum(r, Enum, endian) catch |err| switch (err) {
error.InvalidEnumTag => unreachable,
else => |e| return e,
};
}