1
Fork 0

simplify catch

main
Motiejus Jakštys 2022-02-20 09:19:59 +02:00 committed by Motiejus Jakštys
parent 988ab9f6d4
commit 9487194c95
1 changed files with 2 additions and 4 deletions

View File

@ -48,13 +48,11 @@ pub const UserWriter = struct {
const fromUserErr = error{InvalidRecord}; const fromUserErr = error{InvalidRecord};
pub fn downCast(comptime T: type, n: u64) fromUserErr!T { pub fn downCast(comptime T: type, n: u64) fromUserErr!T {
if (std.math.cast(T, n)) |result| { return std.math.cast(T, n) catch |err| switch (err) {
return result;
} else |err| switch (err) {
error.Overflow => { error.Overflow => {
return error.InvalidRecord; return error.InvalidRecord;
}, },
} };
} }
pub fn appendUser(self: *UserWriter, user: User) !void { pub fn appendUser(self: *UserWriter, user: User) !void {