I’m not sure if this has been discussed somewhere already, but I wanted to get feedback on this idea, whether it’s feasible and whether it aligns with the direction of the Zig language.
As we know Zig has file level structs that we can define as follows:
const Foo = @This();
value: i32,
pub fn init(val: i32) Foo {
return .{
.value = val,
};
}
and we can use it like this:
const Foo = @import("foo.zig");
const foo = Foo.init(10);
I wanted to ask if this could be possible for union(enum)
const UnionEnum = union(enum) {
A: struct {a: i32, b:i32},
B: struct {c: bool},
}
can be:
// We can define something like this:
const UnionEnum = @union(enum);
A: struct {a: i32, b:i32},
B: struct {c: bool},
and it would work as same principle.
This is just an idea that I came up please don’t take it too seriously just wanted to learn if its feasible or not.
Thank you in advance.