Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
pub usingnamespace @import("counting.zig");
const std = @import("std");
pub fn CountingReader(comptime ReaderType: type) type {
return struct {
underlying_stream: ReaderType,
distance: usize = 0,
pub const Error = ReaderType.Error;
pub const Reader = std.io.Reader(*Self, Error, read);
const Self = @This();
fn read(self: *Self, dest: []u8) Error!usize {
const len = try self.underlying_stream.read(dest);
self.distance += len;
return len;
}
pub fn reader(self: *Self) Reader {
return .{ .context = self };
}
};
}
pub fn countingReader(underlying_stream: anytype) CountingReader(@TypeOf(underlying_stream)) {
return .{ .underlying_stream = underlying_stream };
}
id: urhg9x9nqtskxsmy9sssyrzq39my3qez696vhccw
name: more_readers
main: _more_readers.zig
license: MIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment