I'm trying to read some serialized data. The dst variable is a pointer to some integer. Tag is an enum { u64, u32 }. The following code works:
switch (tag) {
.u64 => dst.* = @intCast(try self.raw.takeInt(u64, .little)),
.u32 => dst.* = @intCast(try self.raw.takeInt(u32, .little)),
else => return error.GarbageData,
}
However, if dst happens to be u32 and the tag is u64, and the value is too big, this would panic. I would like to return an error in that case. But if I try to use std.math.cast, I get compilation errors because the tag isn't compile time known...