remove usingnamespace from asyncio

Eliminate the final usingnamespace usage, which will be deprecated in version 0.15.0.
This commit is contained in:
Tarry Singh 2025-05-05 09:03:06 +00:00
parent ed5ae31338
commit db303a6010

View File

@ -115,10 +115,10 @@ pub const TCP = struct {
exec: *Executor, exec: *Executor,
tcp: xev.TCP, tcp: xev.TCP,
pub usingnamespace Closeable(Self, xev.TCP); pub const close = Closeable(Self, xev.TCP);
pub usingnamespace Pollable(Self, xev.TCP); pub const poll = Pollable(Self, xev.TCP);
pub usingnamespace Readable(Self, xev.TCP); pub const read = Readable(Self, xev.TCP);
pub usingnamespace Writeable(Self, xev.TCP); pub const write = Writeable(Self, xev.TCP);
pub fn init(exec: *Executor, tcp: xev.TCP) Self { pub fn init(exec: *Executor, tcp: xev.TCP) Self {
return .{ .exec = exec, .tcp = tcp }; 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 { return struct {
const Self = T; const Self = T;
const CloseResult = xev.CloseError!void; const CloseResult = xev.CloseError!void;
pub fn close(self: Self) !void { pub fn close(self: Self) anyerror!void {
const ResultT = CloseResult; const ResultT = CloseResult;
const Data = struct { const Data = struct {
result: ResultT = undefined, result: ResultT = undefined,
@ -251,14 +260,13 @@ fn Closeable(comptime T: type, comptime StreamT: type) type {
return data.result; 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 { return struct {
const Self = T;
const PollResult = xev.PollError!void; const PollResult = xev.PollError!void;
pub fn poll(self: Self) !void { pub fn poll(self: T) anyerror!void {
const ResultT = PollResult; const ResultT = PollResult;
const Data = struct { const Data = struct {
result: ResultT = undefined, result: ResultT = undefined,
@ -291,14 +299,14 @@ fn Pollable(comptime T: type, comptime StreamT: type) type {
return data.result; 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 { return struct {
const Self = T; const Self = T;
const ReadResult = xev.ReadError!usize; 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 ResultT = ReadResult;
const Data = struct { const Data = struct {
result: ResultT = undefined, result: ResultT = undefined,
@ -333,10 +341,10 @@ fn Readable(comptime T: type, comptime StreamT: type) type {
return data.result; 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 { return struct {
const Self = T; const Self = T;
const WriteResult = xev.WriteError!usize; const WriteResult = xev.WriteError!usize;
@ -374,7 +382,7 @@ fn Writeable(comptime T: type, comptime StreamT: type) type {
try waitForCompletion(self.exec, &c); try waitForCompletion(self.exec, &c);
return data.result; return data.result;
} }
}; }.write;
} }
pub const File = struct { pub const File = struct {
@ -383,10 +391,10 @@ pub const File = struct {
exec: *Executor, exec: *Executor,
file: xev.File, file: xev.File,
pub usingnamespace Closeable(Self, xev.File); pub const close = Closeable(Self, xev.File);
pub usingnamespace Pollable(Self, xev.File); pub const poll = Pollable(Self, xev.File);
pub usingnamespace Readable(Self, xev.File); pub const read = Readable(Self, xev.File);
pub usingnamespace Writeable(Self, xev.File); pub const write = Writeable(Self, xev.File);
pub fn init(exec: *Executor, file: xev.File) Self { pub fn init(exec: *Executor, file: xev.File) Self {
return .{ .exec = exec, .file = file }; return .{ .exec = exec, .file = file };
@ -527,10 +535,8 @@ pub const UDP = struct {
exec: *Executor, exec: *Executor,
udp: xev.UDP, udp: xev.UDP,
pub usingnamespace Closeable(Self, xev.TCP); pub const close = Closeable(Self, xev.UDP);
pub usingnamespace Pollable(Self, xev.TCP); pub const poll = Pollable(Self, xev.UDP);
pub usingnamespace Readable(Self, xev.TCP);
pub usingnamespace Writeable(Self, xev.TCP);
pub fn init(exec: *Executor, udp: xev.UDP) Self { pub fn init(exec: *Executor, udp: xev.UDP) Self {
return .{ .exec = exec, .udp = udp }; return .{ .exec = exec, .udp = udp };
@ -541,7 +547,7 @@ pub const UDP = struct {
} }
const ReadResult = xev.ReadError!usize; 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 ResultT = ReadResult;
const Data = struct { const Data = struct {
result: ResultT = undefined, result: ResultT = undefined,
@ -582,7 +588,7 @@ pub const UDP = struct {
} }
const WriteResult = xev.WriteError!usize; 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 ResultT = WriteResult;
const Data = struct { const Data = struct {
result: ResultT = undefined, result: ResultT = undefined,