authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-28 12:04:31 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2025-08-28 12:04:31 -07:00
log874ae5c71c029969d4aef1aaea77b6dcbf913289
tree0d81bd930e00c519238ff67e8606ddfab9567b3e
parent19b34143608a825b6d950035c5264f99298cdb19

AnyReadable: move readFn to vtable


1 files changed, 4 insertions(+), 2 deletions(-)

File.zig+4-2
...@@ -27,14 +27,16 @@ pub fn read(self: File, buffer: []u8) ReadError!usize {...@@ -27,14 +27,16 @@ pub fn read(self: File, buffer: []u8) ReadError!usize {
2727
28pub fn anyReadable(self: File) nio.AnyReadable {28pub fn anyReadable(self: File) nio.AnyReadable {
29 const S = struct {29 const S = struct {
30 fn foo(s: *allowzero anyopaque, buffer: []u8) anyerror!usize {30 fn read(s: *allowzero anyopaque, buffer: []u8) anyerror!usize {
31 const fd: nfs.Handle = @enumFromInt(@intFromPtr(s));31 const fd: nfs.Handle = @enumFromInt(@intFromPtr(s));
32 const f: File = .{ .fd = fd };32 const f: File = .{ .fd = fd };
33 return f.read(buffer);33 return f.read(buffer);
34 }34 }
35 };35 };
36 return .{36 return .{
37 .readFn = S.foo,37 .vtable = &.{
38 .read = S.read,
39 },
38 .state = @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(@intFromEnum(self.fd)))))),40 .state = @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(@intFromEnum(self.fd)))))),
39 };41 };
40}42}