turbonss/src/validate.zig
2022-02-27 18:40:05 +02:00

18 lines
422 B
Zig

const std = @import("std");
pub const InvalidRecord = error{InvalidRecord};
pub fn downCast(comptime T: type, n: u64) InvalidRecord!T {
return std.math.cast(T, n) catch |err| switch (err) {
error.Overflow => {
return error.InvalidRecord;
},
};
}
pub fn utf8(s: []const u8) InvalidRecord!void {
if (!std.unicode.utf8ValidateSlice(s)) {
return error.InvalidRecord;
}
}