authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-29 13:18:58 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-05-29 13:18:58 -07:00
log3dbac838d6bf37842a478d47e8fbdd15cddbde7a
tree570939c36592d15a67135d43f671165083d5b009
parent6ea8d9f07367a52b335deaf2dcbb6e44ab6640cd

support printing [N]u8


1 files changed, 21 insertions(+), 0 deletions(-)

src/lib.zig+21
......@@ -113,6 +113,15 @@ inline fn do(alloc: std.mem.Allocator, writer: anytype, comptime value: astgen.V
113113 try writer.writeAll(try x.toString(alloc));
114114 return;
115115 }
116 if (comptime isArrayOf(u8)(TO)) {
117 if (repl.raw) {
118 try writer.writeAll(&x);
119 return;
120 }
121 const s = std.mem.trim(u8, &x, "\n");
122 try writeEscaped(s, writer);
123 return;
124 }
116125 @compileError(std.fmt.comptimePrint("pek: print {s}: unsupported type: {s}", .{ v, @typeName(TO) }));
117126 },
118127 .block => |v| {
......@@ -356,3 +365,15 @@ fn docap(alloc: std.mem.Allocator, writer: anytype, comptime top: astgen.Value,
356365 try do(alloc, writer, bottom, data, ctx, opts);
357366 }
358367}
368
369fn isArrayOf(comptime T: type) std.meta.trait.TraitFn {
370 const Closure = struct {
371 pub fn trait(comptime C: type) bool {
372 return switch (@typeInfo(C)) {
373 .Array => |ti| ti.child == T,
374 else => false,
375 };
376 }
377 };
378 return Closure.trait;
379}