From db303a601075b3f2ca98f2a282b821c90b4a61a2 Mon Sep 17 00:00:00 2001 From: Tarry Singh Date: Mon, 5 May 2025 09:03:06 +0000 Subject: [PATCH] remove usingnamespace from asyncio Eliminate the final usingnamespace usage, which will be deprecated in version 0.15.0. --- async/asyncio.zig | 58 ++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/async/asyncio.zig b/async/asyncio.zig index 1f41f90..7fe0590 100644 --- a/async/asyncio.zig +++ b/async/asyncio.zig @@ -115,10 +115,10 @@ pub const TCP = struct { exec: *Executor, tcp: xev.TCP, - pub usingnamespace Closeable(Self, xev.TCP); - pub usingnamespace Pollable(Self, xev.TCP); - pub usingnamespace Readable(Self, xev.TCP); - pub usingnamespace Writeable(Self, xev.TCP); + pub const close = Closeable(Self, xev.TCP); + pub const poll = Pollable(Self, xev.TCP); + pub const read = Readable(Self, xev.TCP); + pub const write = Writeable(Self, xev.TCP); pub fn init(exec: *Executor, tcp: xev.TCP) Self { return .{ .exec = exec, .tcp = tcp }; @@ -214,11 +214,20 @@ pub const TCP = struct { } }; -fn Closeable(comptime T: type, comptime StreamT: type) type { +pub const AsyncError = error{ + AccessDenied, + EventNotFound, + SystemResources, + ProcessNotFound, + Overflow, + NestedRunsNotAllowed, +}; + +fn Closeable(comptime T: type, comptime StreamT: type) fn (T) anyerror!void { return struct { const Self = T; const CloseResult = xev.CloseError!void; - pub fn close(self: Self) !void { + pub fn close(self: Self) anyerror!void { const ResultT = CloseResult; const Data = struct { result: ResultT = undefined, @@ -251,14 +260,13 @@ fn Closeable(comptime T: type, comptime StreamT: type) type { return data.result; } - }; + }.close; } -fn Pollable(comptime T: type, comptime StreamT: type) type { +fn Pollable(comptime T: type, comptime StreamT: type) fn (T) anyerror!void { return struct { - const Self = T; const PollResult = xev.PollError!void; - pub fn poll(self: Self) !void { + pub fn poll(self: T) anyerror!void { const ResultT = PollResult; const Data = struct { result: ResultT = undefined, @@ -291,14 +299,14 @@ fn Pollable(comptime T: type, comptime StreamT: type) type { return data.result; } - }; + }.poll; } -fn Readable(comptime T: type, comptime StreamT: type) type { +fn Readable(comptime T: type, comptime StreamT: type) fn (T, xev.ReadBuffer) anyerror!usize { return struct { const Self = T; const ReadResult = xev.ReadError!usize; - pub fn read(self: Self, buf: xev.ReadBuffer) !usize { + pub fn read(self: Self, buf: xev.ReadBuffer) anyerror!usize { const ResultT = ReadResult; const Data = struct { result: ResultT = undefined, @@ -333,10 +341,10 @@ fn Readable(comptime T: type, comptime StreamT: type) type { return data.result; } - }; + }.read; } -fn Writeable(comptime T: type, comptime StreamT: type) type { +fn Writeable(comptime T: type, comptime StreamT: type) fn (T, xev.WriteBuffer) anyerror!usize { return struct { const Self = T; const WriteResult = xev.WriteError!usize; @@ -374,7 +382,7 @@ fn Writeable(comptime T: type, comptime StreamT: type) type { try waitForCompletion(self.exec, &c); return data.result; } - }; + }.write; } pub const File = struct { @@ -383,10 +391,10 @@ pub const File = struct { exec: *Executor, file: xev.File, - pub usingnamespace Closeable(Self, xev.File); - pub usingnamespace Pollable(Self, xev.File); - pub usingnamespace Readable(Self, xev.File); - pub usingnamespace Writeable(Self, xev.File); + pub const close = Closeable(Self, xev.File); + pub const poll = Pollable(Self, xev.File); + pub const read = Readable(Self, xev.File); + pub const write = Writeable(Self, xev.File); pub fn init(exec: *Executor, file: xev.File) Self { return .{ .exec = exec, .file = file }; @@ -527,10 +535,8 @@ pub const UDP = struct { exec: *Executor, udp: xev.UDP, - pub usingnamespace Closeable(Self, xev.TCP); - pub usingnamespace Pollable(Self, xev.TCP); - pub usingnamespace Readable(Self, xev.TCP); - pub usingnamespace Writeable(Self, xev.TCP); + pub const close = Closeable(Self, xev.UDP); + pub const poll = Pollable(Self, xev.UDP); pub fn init(exec: *Executor, udp: xev.UDP) Self { return .{ .exec = exec, .udp = udp }; @@ -541,7 +547,7 @@ pub const UDP = struct { } const ReadResult = xev.ReadError!usize; - pub fn read(self: Self, buf: xev.ReadBuffer) !usize { + pub fn read(self: Self, buf: xev.ReadBuffer) anyerror!usize { const ResultT = ReadResult; const Data = struct { result: ResultT = undefined, @@ -582,7 +588,7 @@ pub const UDP = struct { } const WriteResult = xev.WriteError!usize; - pub fn write(self: Self, addr: std.net.Address, buf: xev.WriteBuffer) !usize { + pub fn write(self: Self, addr: std.net.Address, buf: xev.WriteBuffer) anyerror!usize { const ResultT = WriteResult; const Data = struct { result: ResultT = undefined,