std.json: support stringify for anyerror

master
Andrew Kelley 2020-05-17 17:07:27 -04:00
parent 2a5c0ef7f0
commit feade9ef00
1 changed files with 2 additions and 0 deletions

View File

@ -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" {