| ... | ... | @@ -504,7 +504,6 @@ pub fn Serializer(Writer: type) type { |
| 504 | 504 | .bool, .null => try std.fmt.format(self.writer, "{}", .{val}), |
| 505 | 505 | .enum_literal => try self.ident(@tagName(val)), |
| 506 | 506 | .@"enum" => try self.ident(@tagName(val)), |
| 507 | | .void => try self.writer.writeAll("{}"), |
| 508 | 507 | .pointer => |pointer| { |
| 509 | 508 | // Try to serialize as a string |
| 510 | 509 | const item: ?type = switch (@typeInfo(pointer.child)) { |
| ... | ... | @@ -579,15 +578,21 @@ pub fn Serializer(Writer: type) type { |
| 579 | 578 | }, |
| 580 | 579 | .@"union" => |@"union"| { |
| 581 | 580 | comptime assert(@"union".tag_type != null); |
| 582 | | var container = try self.startStruct(.{ .whitespace_style = .{ .fields = 1 } }); |
| 583 | 581 | switch (val) { |
| 584 | | inline else => |pl, tag| try container.fieldArbitraryDepth( |
| 585 | | @tagName(tag), |
| 586 | | pl, |
| 587 | | options, |
| 588 | | ), |
| 582 | inline else => |pl, tag| if (@TypeOf(pl) == void) |
| 583 | try self.writer.print(".{s}", .{@tagName(tag)}) |
| 584 | else { |
| 585 | var container = try self.startStruct(.{ .whitespace_style = .{ .fields = 1 } }); |
| 586 | |
| 587 | try container.fieldArbitraryDepth( |
| 588 | @tagName(tag), |
| 589 | pl, |
| 590 | options, |
| 591 | ); |
| 592 | |
| 593 | try container.finish(); |
| 594 | }, |
| 589 | 595 | } |
| 590 | | try container.finish(); |
| 591 | 596 | }, |
| 592 | 597 | .optional => if (val) |inner| { |
| 593 | 598 | try self.valueArbitraryDepth(inner, options); |
| ... | ... | @@ -1116,6 +1121,12 @@ test "std.zon stringify whitespace, high level API" { |
| 1116 | 1121 | \\ 3, |
| 1117 | 1122 | \\} } |
| 1118 | 1123 | , .{ .inner = .{ 1, 2, 3 } }, .{}); |
| 1124 | |
| 1125 | const UnionWithVoid = union(enum) { a, b: void, c: u8 }; |
| 1126 | |
| 1127 | try expectSerializeEqual( |
| 1128 | \\.a |
| 1129 | , UnionWithVoid.a, .{}); |
| 1119 | 1130 | } |
| 1120 | 1131 | |
| 1121 | 1132 | test "std.zon stringify whitespace, low level API" { |