lib: add a TaggedUnion helper to create C ABI compatible tagged unions

This commit is contained in:
Mitchell Hashimoto
2025-10-23 14:03:34 -07:00
parent fb5b8d7968
commit 099dcbe04d
6 changed files with 214 additions and 6 deletions

View File

@@ -1,4 +1,5 @@
const std = @import("std");
const Target = @import("target.zig").Target;
/// Create an enum type with the given keys that is C ABI compatible
/// if we're targeting C, otherwise a Zig enum with smallest possible
@@ -58,11 +59,6 @@ pub fn Enum(
return Result;
}
pub const Target = union(enum) {
c,
zig,
};
test "zig" {
const testing = std.testing;
const T = Enum(.zig, &.{ "a", "b", "c", "d" });