diff --git a/AnyReadable.zig b/AnyReadable.zig index b649e3e5c62b1fbf5d9c114e296f0142e84df07d..e83fd6f433d5d37c581521ce0bff964538374a61 100644 --- a/AnyReadable.zig +++ b/AnyReadable.zig @@ -8,9 +8,23 @@ vtable: *const struct { }, state: *allowzero anyopaque, +const R = nio.Readable(@This(), ._const); +pub const readAll = R.readAll; +pub const readAtLeast = R.readAtLeast; +pub const readNoEof = R.readNoEof; +pub const readAllAlloc = R.readAllAlloc; +pub const readArray = R.readArray; +pub const readByte = R.readByte; +pub const readUntilDelimiterArrayList = R.readUntilDelimiterArrayList; +pub const readUntilDelimiterAlloc = R.readUntilDelimiterAlloc; +pub const readUntilDelimitersBuf = R.readUntilDelimitersBuf; +pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; +pub const readAlloc = R.readAlloc; +pub const readInt = R.readInt; +pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; + pub const Error = ReadError; // std compat pub const ReadError = anyerror; -pub usingnamespace nio.Readable(@This(), ._const); pub fn read(r: AnyReadable, buffer: []u8) !usize { return r.vtable.read(r.state, buffer); } diff --git a/AnyWritable.zig b/AnyWritable.zig index ede853a09f85d497a6c2b7e122015a11f087412b..6981eae01cd528ee096c60fed4403da87441abf3 100644 --- a/AnyWritable.zig +++ b/AnyWritable.zig @@ -15,8 +15,17 @@ vtable: *const struct { }, state: *allowzero anyopaque, +const W = nio.Writable(@This(), ._const); +pub const writeAll = W.writeAll; +pub const writevAll = W.writevAll; +pub const writeByteNTimes = W.writeByteNTimes; +pub const writeNTimes = W.writeNTimes; +pub const writeInt = W.writeInt; +pub const writeStruct = W.writeStruct; +pub const writeIntPretty = W.writeIntPretty; +pub const print = W.print; + pub const WriteError = anyerror; -pub usingnamespace nio.Writable(@This(), ._const); pub fn write(r: AnyWritable, buffer: []const u8) !usize { return r.vtable.write(r.state, buffer); } diff --git a/buffered_reader.zig b/buffered_reader.zig index cf346fba5a1b4a41958948276563d2383ca07196..c4831041804a1d4b989fed147155f625f923b7e3 100644 --- a/buffered_reader.zig +++ b/buffered_reader.zig @@ -19,8 +19,22 @@ pub fn BufferedReader(comptime buffer_size: usize, comptime ReaderType: type) ty }; } + const R = nio.Readable(@This(), ._var); + pub const readAll = R.readAll; + pub const readAtLeast = R.readAtLeast; + pub const readNoEof = R.readNoEof; + pub const readAllAlloc = R.readAllAlloc; + pub const readArray = R.readArray; + pub const readByte = R.readByte; + pub const readUntilDelimiterArrayList = R.readUntilDelimiterArrayList; + pub const readUntilDelimiterAlloc = R.readUntilDelimiterAlloc; + pub const readUntilDelimitersBuf = R.readUntilDelimitersBuf; + pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; + pub const readAlloc = R.readAlloc; + pub const readInt = R.readInt; + pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; + pub const ReadError = ReaderType.ReadError; - pub usingnamespace nio.Readable(@This(), ._var); pub fn read(self: *Self, dest: []u8) ReadError!usize { // First try reading from the already buffered data onto the destination. const current = self.buf[self.start..self.end]; diff --git a/buffered_writer.zig b/buffered_writer.zig index 8c02126a59943181000f076be653aec76a0d0844..62ca73411bead8512732870bc43cb78aaeff4982 100644 --- a/buffered_writer.zig +++ b/buffered_writer.zig @@ -25,8 +25,17 @@ pub fn BufferedWriter(comptime buffer_size: usize, comptime WriterType: type) ty }; } + const W = nio.Writable(@This(), ._var); + pub const writeAll = W.writeAll; + pub const writevAll = W.writevAll; + pub const writeByteNTimes = W.writeByteNTimes; + pub const writeNTimes = W.writeNTimes; + pub const writeInt = W.writeInt; + pub const writeStruct = W.writeStruct; + pub const writeIntPretty = W.writeIntPretty; + pub const print = W.print; + pub const WriteError = extras.Pointee(WriterType).WriteError; - pub usingnamespace nio.Writable(@This(), ._var); pub fn write(self: *Self, bytes: []const u8) WriteError!usize { if (self.end + bytes.len > self.buf.len) { try self.flush(); diff --git a/counting_writer.zig b/counting_writer.zig index 291ea5cb5bd75e871a3e756392350367cbcee702..92691b8615844a5db553ccdbf590793620f57c64 100644 --- a/counting_writer.zig +++ b/counting_writer.zig @@ -16,8 +16,17 @@ pub fn CountingWriter(WriterType: type) type { }; } + const W = nio.Writable(@This(), ._var); + pub const writeAll = W.writeAll; + pub const writevAll = W.writevAll; + pub const writeByteNTimes = W.writeByteNTimes; + pub const writeNTimes = W.writeNTimes; + pub const writeInt = W.writeInt; + pub const writeStruct = W.writeStruct; + pub const writeIntPretty = W.writeIntPretty; + pub const print = W.print; + pub const WriteError = extras.Pointee(WriterType).WriteError; - pub usingnamespace nio.Writable(@This(), ._var); pub fn write(self: *Self, bytes: []const u8) WriteError!usize { const len = try self.backing_writer.write(bytes); self.bytes_written += len; diff --git a/fixed_buffer_stream.zig b/fixed_buffer_stream.zig index 6db0980b738cba756b01995a9807e9f04e431018..9af8fbe6d2b3a40968ef435e76f375bac670b8fb 100644 --- a/fixed_buffer_stream.zig +++ b/fixed_buffer_stream.zig @@ -27,8 +27,22 @@ pub fn FixedBufferStream(comptime Buffer: type) type { }; } + const R = nio.Readable(@This(), ._var); + pub const readAll = R.readAll; + pub const readAtLeast = R.readAtLeast; + pub const readNoEof = R.readNoEof; + pub const readAllAlloc = R.readAllAlloc; + pub const readArray = R.readArray; + pub const readByte = R.readByte; + pub const readUntilDelimiterArrayList = R.readUntilDelimiterArrayList; + pub const readUntilDelimiterAlloc = R.readUntilDelimiterAlloc; + pub const readUntilDelimitersBuf = R.readUntilDelimitersBuf; + pub const readUntilDelimitersArrayList = R.readUntilDelimitersArrayList; + pub const readAlloc = R.readAlloc; + pub const readInt = R.readInt; + pub const readUntilDelimitersAlloc = R.readUntilDelimitersAlloc; + pub const ReadError = error{}; - pub usingnamespace nio.Readable(@This(), ._var); pub fn read(self: *Self, dest: []u8) ReadError!usize { const size = @min(dest.len, self.buffer.len - self.pos); const end = self.pos + size; @@ -50,8 +64,17 @@ pub fn FixedBufferStream(comptime Buffer: type) type { }; } + const W = nio.Writable(@This(), ._var); + pub const writeAll = W.writeAll; + pub const writevAll = W.writevAll; + pub const writeByteNTimes = W.writeByteNTimes; + pub const writeNTimes = W.writeNTimes; + pub const writeInt = W.writeInt; + pub const writeStruct = W.writeStruct; + pub const writeIntPretty = W.writeIntPretty; + pub const print = W.print; + pub const WriteError = error{NoSpaceLeft}; - pub usingnamespace nio.Writable(@This(), ._var); /// If the returned number of bytes written is less than requested, the buffer is full. /// Returns `error.NoSpaceLeft` when no bytes would be written. pub fn write(self: *Self, bytes: []const u8) WriteError!usize { diff --git a/null_writer.zig b/null_writer.zig index 23db0828bf021d5f151bfc1fbe86184242bba7a3..f543a2f0f79f160e098212c9d24ad0090fecd6f6 100644 --- a/null_writer.zig +++ b/null_writer.zig @@ -3,8 +3,17 @@ const extras = @import("extras"); const nio = @import("./nio.zig"); pub const NullWriter = struct { + const W = nio.Writable(@This(), ._var); + pub const writeAll = W.writeAll; + pub const writevAll = W.writevAll; + pub const writeByteNTimes = W.writeByteNTimes; + pub const writeNTimes = W.writeNTimes; + pub const writeInt = W.writeInt; + pub const writeStruct = W.writeStruct; + pub const writeIntPretty = W.writeIntPretty; + pub const print = W.print; + pub const WriteError = error{}; - pub usingnamespace nio.Writable(@This(), ._var); pub fn write(self: NullWriter, bytes: []const u8) WriteError!usize { _ = self; return bytes.len;