| ... | @@ -618,10 +618,6 @@ pub fn writeAllPreserve(w: *Writer, preserve_length: usize, bytes: []const u8) E | ... | @@ -618,10 +618,6 @@ pub fn writeAllPreserve(w: *Writer, preserve_length: usize, bytes: []const u8) E |
| 618 | /// A user type may be a `struct`, `vector`, `union` or `enum` type. | 618 | /// A user type may be a `struct`, `vector`, `union` or `enum` type. |
| 619 | /// | 619 | /// |
| 620 | /// To print literal curly braces, escape them by writing them twice, e.g. `{{` or `}}`. | 620 | /// To print literal curly braces, escape them by writing them twice, e.g. `{{` or `}}`. |
| 621 | /// | | |
| 622 | /// Asserts `buffer` capacity of at least 2 if a union is printed. This | | |
| 623 | /// requirement could be lifted by adjusting the code, but if you trigger that | | |
| 624 | /// assertion it is a clue that you should probably be using a buffer. | | |
| 625 | pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void { | 621 | pub fn print(w: *Writer, comptime fmt: []const u8, args: anytype) Error!void { |
| 626 | const ArgsType = @TypeOf(args); | 622 | const ArgsType = @TypeOf(args); |
| 627 | const args_type_info = @typeInfo(ArgsType); | 623 | const args_type_info = @typeInfo(ArgsType); |
| ... | @@ -1257,14 +1253,13 @@ pub fn printValue( | ... | @@ -1257,14 +1253,13 @@ pub fn printValue( |
| 1257 | .@"extern", .@"packed" => { | 1253 | .@"extern", .@"packed" => { |
| 1258 | if (info.fields.len == 0) return w.writeAll(".{}"); | 1254 | if (info.fields.len == 0) return w.writeAll(".{}"); |
| 1259 | try w.writeAll(".{ "); | 1255 | try w.writeAll(".{ "); |
| 1260 | inline for (info.fields) |field| { | 1256 | inline for (info.fields, 1..) |field, i| { |
| 1261 | try w.writeByte('.'); | 1257 | try w.writeByte('.'); |
| 1262 | try w.writeAll(field.name); | 1258 | try w.writeAll(field.name); |
| 1263 | try w.writeAll(" = "); | 1259 | try w.writeAll(" = "); |
| 1264 | try w.printValue(ANY, options, @field(value, field.name), max_depth - 1); | 1260 | try w.printValue(ANY, options, @field(value, field.name), max_depth - 1); |
| 1265 | (try w.writableArray(2)).* = ", ".*; | 1261 | try w.writeAll(if (i < info.fields.len) ", " else " }"); |
| 1266 | } | 1262 | } |
| 1267 | w.buffer[w.end - 2 ..][0..2].* = " }".*; | | |
| 1268 | }, | 1263 | }, |
| 1269 | } | 1264 | } |
| 1270 | }, | 1265 | }, |