langref: add documentation for unions with inferred tag and explicit tag values
This commit is contained in:
committed by
Andrew Kelley
parent
c315f2bc2e
commit
cf90a5e451
17
doc/langref/test_tagged_union_with_tag_values.zig
Normal file
17
doc/langref/test_tagged_union_with_tag_values.zig
Normal file
@@ -0,0 +1,17 @@
|
||||
const std = @import("std");
|
||||
const expect = std.testing.expect;
|
||||
|
||||
const Tagged = union(enum(u32)) {
|
||||
int: i64 = 123,
|
||||
boolean: bool = 67,
|
||||
};
|
||||
|
||||
test "tag values" {
|
||||
const int: Tagged = .{ .int = -40 };
|
||||
try expect(@intFromEnum(int) == 123);
|
||||
|
||||
const boolean: Tagged = .{ .boolean = false };
|
||||
try expect(@intFromEnum(boolean) == 67);
|
||||
}
|
||||
|
||||
// test
|
||||
Reference in New Issue
Block a user