diff --git a/counting_writer.zig b/counting_writer.zig index d54a35318fc41e62b1b85e0d7ca171bba947fa19..a17393254e9b41c0536e57b7d4b8be54b5b2e36b 100644 --- a/counting_writer.zig +++ b/counting_writer.zig @@ -43,5 +43,18 @@ pub fn CountingWriter(WriterType: type) type { self.bytes_written += len; return len; } + + pub fn anyWritable(self: *Self) nio.AnyWritable { + const S = struct { + fn write(s: *allowzero anyopaque, buffer: []const u8) anyerror!usize { + const cw: *Self = @ptrCast(@alignCast(s)); + return cw.write(buffer); + } + }; + return .{ + .vtable = &.{ .write = S.write }, + .state = @ptrCast(self), + }; + } }; }