simplify catch

This commit is contained in:
Motiejus Jakštys 2022-02-20 09:19:59 +02:00 committed by Motiejus Jakštys
parent 988ab9f6d4
commit 9487194c95

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 {