mirror of
https://github.com/ziglang/zig.git
synced 2026-01-07 14:03:26 +00:00
std.json: support stringify for anyerror
This commit is contained in:
parent
2a5c0ef7f0
commit
feade9ef00
@ -2434,6 +2434,7 @@ pub fn stringify(
|
||||
|
||||
@compileError("Unable to stringify enum '" ++ @typeName(T) ++ "'");
|
||||
},
|
||||
.ErrorSet => return out_stream.writeAll(@errorName(value)),
|
||||
.Union => {
|
||||
if (comptime std.meta.trait.hasFn("jsonStringify")(T)) {
|
||||
return value.jsonStringify(options, out_stream);
|
||||
@ -2646,6 +2647,7 @@ test "stringify basic types" {
|
||||
try teststringify("42", @as(u128, 42), StringifyOptions{});
|
||||
try teststringify("4.2e+01", @as(f32, 42), StringifyOptions{});
|
||||
try teststringify("4.2e+01", @as(f64, 42), StringifyOptions{});
|
||||
try teststringify("ItBroke", @as(anyerror, error.ItBroke), StringifyOptions{});
|
||||
}
|
||||
|
||||
test "stringify string" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user