| author | |
| committer | |
| log | 5fe04e96ca6e24364f87aff9a0d348bf2ccac768 |
| tree | edec1e521e9c7e5e226032eec64a69c584b259e4 |
| parent | c95791d223efb5113f17568fc9536d4e19a03900 |
2 files changed, 9 insertions(+), 7 deletions(-)
AnyReadable.zig+5-5| ... | ... | @@ -3,12 +3,12 @@ const std = @import("std"); |
| 3 | 3 | const nio = @import("./nio.zig"); |
| 4 | 4 | const AnyReadable = @This(); |
| 5 | 5 | |
| 6 | readFn: *const fn (*allowzero anyopaque, []u8) anyerror!usize, | |
| 6 | vtable: *const struct { | |
| 7 | }, | |
| 7 | 8 | state: *allowzero anyopaque, |
| 8 | 9 | |
| 9 | pub fn read(r: *AnyReadable, buffer: []u8) !usize { | |
| 10 | return r.readFn(r.state, buffer); | |
| 11 | } | |
| 12 | ||
| 13 | 10 | pub const ReadError = anyerror; |
| 14 | 11 | pub usingnamespace nio.Readable(@This(), ._var); |
| 12 | pub fn read(r: *AnyReadable, buffer: []u8) !usize { | |
| 13 | return r.vtable.read(r.state, buffer); | |
| 14 | } |
fixed_buffer_stream.zig+4-2| ... | ... | @@ -29,13 +29,15 @@ pub fn FixedBufferStream(comptime Buffer: type) type { |
| 29 | 29 | |
| 30 | 30 | pub fn anyReadable(self: *Self) nio.AnyReadable { |
| 31 | 31 | const S = struct { |
| 32 | fn foo(s: *allowzero anyopaque, buffer: []u8) anyerror!usize { | |
| 32 | fn read(s: *allowzero anyopaque, buffer: []u8) anyerror!usize { | |
| 33 | 33 | const fbs: *Self = @ptrCast(@alignCast(s)); |
| 34 | 34 | return fbs.read(buffer); |
| 35 | 35 | } |
| 36 | 36 | }; |
| 37 | 37 | return .{ |
| 38 | .readFn = S.foo, | |
| 38 | .vtable = &.{ | |
| 39 | .read = S.read, | |
| 40 | }, | |
| 39 | 41 | .state = @ptrCast(self), |
| 40 | 42 | }; |
| 41 | 43 | } |