| ... | @@ -207,3 +207,26 @@ pub fn pipe(reader_from: anytype, writer_to: anytype) !void { | ... | @@ -207,3 +207,26 @@ pub fn pipe(reader_from: anytype, writer_to: anytype) !void { |
| 207 | defer fifo.deinit(); | 207 | defer fifo.deinit(); |
| 208 | try fifo.pump(reader_from, writer_to); | 208 | try fifo.pump(reader_from, writer_to); |
| 209 | } | 209 | } |
| | 210 | |
| | 211 | pub fn StringerJsonStringifyMixin(comptime S: type) type { |
| | 212 | return struct { |
| | 213 | pub fn jsonStringify(self: S, options: std.json.StringifyOptions, out_stream: anytype) !void { |
| | 214 | var buf: [1024]u8 = undefined; |
| | 215 | var fba = std.heap.FixedBufferAllocator.init(&buf); |
| | 216 | const alloc = fba.allocator(); |
| | 217 | var list = std.ArrayList(u8).init(alloc); |
| | 218 | errdefer list.deinit(); |
| | 219 | const writer = list.writer(); |
| | 220 | try writer.writeAll(try self.toString(alloc)); |
| | 221 | try std.json.stringify(list.toOwnedSlice(), options, out_stream); |
| | 222 | } |
| | 223 | }; |
| | 224 | } |
| | 225 | |
| | 226 | pub fn TagNameJsonStringifyMixin(comptime S: type) type { |
| | 227 | return struct { |
| | 228 | pub fn jsonStringify(self: S, options: std.json.StringifyOptions, out_stream: anytype) !void { |
| | 229 | try std.json.stringify(@tagName(self), options, out_stream); |
| | 230 | } |
| | 231 | }; |
| | 232 | } |