std.math.cast returns optional

This commit is contained in:
Lee Cannon 2022-05-29 18:17:43 +01:00
parent b9351ca722
commit 106e3cd963
No known key found for this signature in database
GPG Key ID: 983D5E5CC5E1401F

View File

@ -114,11 +114,11 @@ fn fromDynamicTreeInternal(arena: *std.heap.ArenaAllocator, value: std.json.Valu
if (value != .Integer) return error.MalformedJson; if (value != .Integer) return error.MalformedJson;
out.* = std.meta.intToEnum( out.* = std.meta.intToEnum(
T, T,
std.math.cast(TagType, value.Integer) catch return error.MalformedJson, std.math.cast(TagType, value.Integer) orelse return error.MalformedJson,
) catch return error.MalformedJson; ) catch return error.MalformedJson;
} else if (comptime std.meta.trait.is(.Int)(T)) { } else if (comptime std.meta.trait.is(.Int)(T)) {
if (value != .Integer) return error.MalformedJson; if (value != .Integer) return error.MalformedJson;
out.* = std.math.cast(T, value.Integer) catch return error.MalformedJson; out.* = std.math.cast(T, value.Integer) orelse return error.MalformedJson;
} else switch (T) { } else switch (T) {
bool => { bool => {
if (value != .Bool) return error.MalformedJson; if (value != .Bool) return error.MalformedJson;