add ability to have custom stringification
This commit is contained in:
parent
c6b3f8d6e1
commit
c80a65ed50
|
@ -1410,7 +1410,7 @@ fn parsedEqual(a: anytype, b: @TypeOf(a)) bool {
|
|||
if (a == null or b == null) return false;
|
||||
return parsedEqual(a.?, b.?);
|
||||
},
|
||||
.Union => {
|
||||
.Union => |info| {
|
||||
if (info.tag_type) |UnionTag| {
|
||||
const tag_a = std.meta.activeTag(a);
|
||||
const tag_b = std.meta.activeTag(b);
|
||||
|
@ -2866,6 +2866,11 @@ pub fn stringify(
|
|||
try out_stream.writeByte('\n');
|
||||
try child_whitespace.outputIndent(out_stream);
|
||||
}
|
||||
var field_written = false;
|
||||
if (comptime std.meta.trait.hasFn("jsonStringifyField")(T))
|
||||
field_written = try value.jsonStringifyField(Field.name, child_options, out_stream);
|
||||
|
||||
if (!field_written) {
|
||||
if (comptime std.meta.trait.hasFn("jsonFieldNameFor")(T)) {
|
||||
const name = value.jsonFieldNameFor(Field.name);
|
||||
try stringify(name, options, out_stream);
|
||||
|
@ -2881,6 +2886,7 @@ pub fn stringify(
|
|||
}
|
||||
try stringify(@field(value, Field.name), child_options, out_stream);
|
||||
}
|
||||
}
|
||||
if (field_output) {
|
||||
if (options.whitespace) |whitespace| {
|
||||
try out_stream.writeByte('\n');
|
||||
|
|
Loading…
Reference in New Issue
Block a user