New Idea for file level structs
ziggit.dev·6d
🔗Linkers
Preview
Report Post

January 4, 2026, 10:42pm 1

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 wor…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help