fn sliceToInt(comptime T: type, slice: []const u8) !T
fn sliceToInt(comptime T: type, slice: []const u8) !T { if (isNumberFormattedLikeAnInteger(slice)) return std.fmt.parseInt(T, slice, 10); // Try to coerce a float to an integer. const float = try std.fmt.parseFloat(f128, slice); if (@round(float) != float) return error.InvalidNumber; if (float > @as(f128, @floatFromInt(std.math.maxInt(T))) or float < @as(f128, @floatFromInt(std.math.minInt(T)))) return error.Overflow; return @as(T, @intCast(@as(i128, @intFromFloat(float)))); }