| ... | @@ -561,3 +561,30 @@ pub fn FieldUnion(comptime T: type) type { | ... | @@ -561,3 +561,30 @@ pub fn FieldUnion(comptime T: type) type { |
| 561 | .decls = &.{}, | 561 | .decls = &.{}, |
| 562 | } }); | 562 | } }); |
| 563 | } | 563 | } |
| | 564 | |
| | 565 | pub 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 | } |