fn sliceToEnum(comptime T: type, slice: []const u8) !T
fn sliceToEnum(comptime T: type, slice: []const u8) !T { // Check for a named value. if (std.meta.stringToEnum(T, slice)) |value| return value; // Check for a numeric value. if (!isNumberFormattedLikeAnInteger(slice)) return error.InvalidEnumTag; const n = std.fmt.parseInt(@typeInfo(T).@"enum".tag_type, slice, 10) catch return error.InvalidEnumTag; return std.enums.fromInt(T, n) orelse return error.InvalidEnumTag; }