-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make std_options a comptime struct instead of a namespace #14432
Comments
I'm a fan of this, and at present it poses no immediate problems. IMO that isn't actually a strong argument against the proposal, because I can't actually imagine any use cases where any of that would be really necessary, so despite that, I'm in favor of this change. |
The reason I went with a namespace instead of a struct instance is |
Ah, that's unfortunate Assuming blocking io can't ever have an event loop, a tagged union could be used: .io = .blocking,
.io = .{ .evented = .{} },
.io = .{ .evented = .{
.event_loop = …,
} }, Or io_mode could be removed entirely: event_loop: event.Loop.Instance
.event_loop = null, // blocking
.event_loop = std.event.default_instance, // default evented
.event_loop = custom, // custom evented If blocking io is allowed to have an event loop, I'm not sure how to resolve the dependency without it being messy |
I oppose this proposal because of the problems of self-referential declarations. Makes it pretty much impossible to depend on Additionally if there are options that let you declare types and implementations of those types, you'd be forced into the annoying pattern of specifying |
Accepted as long as we can solve the issue that @Vexu mentioned. |
@pfgithub I'm not sure what issue remains with a tagged union approach. Is this what you considered being messy?:
// in @import("std") somewhere
const IoConfig = union(enum) {
const Blocking = struct{
EventLoopType: ?type = null,
fn EventLoop(b: Blocking) type {
return b.EventLoopType orelse DefaultBlockingModeEventLoop;
}
};
const Evented = struct{
EventLoopType: ?type = null,
fn EventLoop(e: Evented) type {
return e.EventLoopType orelse DefaultEventedModeEventLoop;
}
};
blocking: Blocking,
evented: Evented,
const Mode = @typeInfo(@This()).Union.tag_type.?;
};
// usage examples:
const io_config_0: IoConfig = .{.blocking = .{}};
const io_config_1 = .{.evented = .{}};
const io_config_2 = .{.blocking = .{
.EventLoopType = CustomEventLoopForBlocking,
} };
const io_config_3 = .{.evented = .{
.EventLoopType = CustomEventLoopForEvented,
} }; |
This would:
Implementation in the standard library:
The text was updated successfully, but these errors were encountered: