simplify catch
This commit is contained in:
parent
988ab9f6d4
commit
9487194c95
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user