authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-16 18:11:22 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-10-16 18:11:22 -07:00
log56919ce43dcc3ecee22eb7d51e90dcef0ce7f4bb
tree4e0e903296558f691407113d70a1f4b4006f1185
parentaaef4127e180916d1466e6598b616818a751a14c

allow printing any struct value that has a toString method


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

src/lib.zig+4
...@@ -88,6 +88,10 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value,...@@ -88,6 +88,10 @@ fn do(alloc: *std.mem.Allocator, writer: anytype, comptime value: astgen.Value,
88 try writer.print("{d}", .{x});88 try writer.print("{d}", .{x});
89 return;89 return;
90 }90 }
91 if (comptime std.meta.trait.hasFn("toString")(TO)) {
92 try writer.writeAll(try x.toString(alloc));
93 return;
94 }
91 @compileError("pek: print: unsupported type: " ++ @typeName(TO));95 @compileError("pek: print: unsupported type: " ++ @typeName(TO));
92 },96 },
93 .block => |v| {97 .block => |v| {