authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-09 13:42:19 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2023-07-09 13:42:19 -07:00
loga81515cba8b6d79513f70f5062f1c2e9c416549b
tree1c6fe2a4b6eae20991edae574cde2248255b9d22
parentcfeeff77833f0e180e116859b2c7370a7c38d8f0

add LoggingReader


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

src/lib.zig+27
......@@ -561,3 +561,30 @@ pub fn FieldUnion(comptime T: type) type {
561561 .decls = &.{},
562562 } });
563563}
564
565pub fn LoggingReader(comptime T: type, comptime scope: @Type(.EnumLiteral)) type {
566 return struct {
567 child_stream: T,
568
569 pub const Error = T.Error;
570 pub const Reader = std.io.Reader(Self, Error, read);
571
572 const Self = @This();
573
574 pub fn init(child_stream: T) Self {
575 return .{
576 .child_stream = child_stream,
577 };
578 }
579
580 pub fn reader(self: Self) Reader {
581 return .{ .context = self };
582 }
583
584 fn read(self: Self, dest: []u8) Error!usize {
585 const n = try self.child_stream.read(dest);
586 std.log.scoped(scope).debug("{s}", .{dest[0..n]});
587 return n;
588 }
589 };
590}