std: add support to std.json.stringify for null literals

This commit is contained in:
daurnimator 2020-02-25 20:37:48 +11:00
parent 62fbb6b874
commit a32d88f12c
No known key found for this signature in database
GPG Key ID: 45B429A8F9D9D22A

View File

@ -1239,7 +1239,7 @@ pub const Value = union(enum) {
out_stream: var,
) @TypeOf(out_stream).Error!void {
switch (value) {
.Null => try out_stream.writeAll("null"),
.Null => try stringify(null, options, out_stream),
.Bool => |inner| try stringify(inner, options, out_stream),
.Integer => |inner| try stringify(inner, options, out_stream),
.Float => |inner| try stringify(inner, options, out_stream),
@ -2414,11 +2414,14 @@ pub fn stringify(
.Bool => {
return out_stream.writeAll(if (value) "true" else "false");
},
.Null => {
return out_stream.writeAll("null");
},
.Optional => {
if (value) |payload| {
return try stringify(payload, options, out_stream);
} else {
return out_stream.writeAll("null");
return try stringify(null, options, out_stream);
}
},
.Enum => {