tangled
alpha
login
or
join now
altagos.dev
/
space
0
fork
atom
A SpaceTraders Agent
0
fork
atom
overview
issues
pulls
pipelines
create function to combine multiple enums into one
altagos.dev
3 months ago
e313b3f7
0a2b039f
verified
This commit was signed with the committer's
known signature
.
altagos.dev
SSH Key Fingerprint:
SHA256:UbTjEcCZlc6GzQWLCuDK3D//HESWD2xFPkzue9XMras=
+34
1 changed file
expand all
collapse all
unified
split
src
meta
root.zig
+34
src/meta/root.zig
···
1
1
pub const fmt = @import("fmt.zig");
2
2
3
3
pub const pretty = fmt.pretty;
4
4
+
5
5
+
pub fn CombinedEnum(comptime parent: type) type {
6
6
+
const std = @import("std");
7
7
+
const parent_info = @typeInfo(parent).@"struct";
8
8
+
9
9
+
var num_fields = 0;
10
10
+
11
11
+
for (parent_info.decls) |partial| {
12
12
+
switch (@typeInfo(@FieldType(parent, partial.name))) {
13
13
+
.@"enum" => |_| num_fields += 1,
14
14
+
else => {},
15
15
+
}
16
16
+
}
17
17
+
18
18
+
var combined: [num_fields]std.builtin.Type.EnumField = undefined;
19
19
+
20
20
+
var i = 0;
21
21
+
for (parent_info.decls) |partial| {
22
22
+
switch (@typeInfo(@FieldType(parent, partial.name))) {
23
23
+
.@"enum" => |e| {
24
24
+
for (e.fields) |field| {
25
25
+
combined[i] = field;
26
26
+
i += 1;
27
27
+
}
28
28
+
},
29
29
+
else => {},
30
30
+
}
31
31
+
}
32
32
+
33
33
+
return @Type(.{ .@"enum" = .{
34
34
+
.decls = &.{},
35
35
+
.fields = &combined,
36
36
+
} });
37
37
+
}