2022-04-27 21:59:55 +01:00
|
|
|
const Number = enum { One, Two, Three };
|
|
|
|
|
|
|
|
pub fn main() void {
|
|
|
|
var number1 = Number.One;
|
|
|
|
var number2: Number = .Two;
|
2023-06-22 18:46:56 +01:00
|
|
|
const number3: Number = @enumFromInt(2);
|
2022-04-27 21:59:55 +01:00
|
|
|
assert(number1 != number2);
|
|
|
|
assert(number2 != number3);
|
2023-06-15 08:14:16 +01:00
|
|
|
assert(@intFromEnum(number1) == 0);
|
|
|
|
assert(@intFromEnum(number2) == 1);
|
|
|
|
assert(@intFromEnum(number3) == 2);
|
2022-04-27 21:59:55 +01:00
|
|
|
var x: Number = .Two;
|
|
|
|
assert(number2 == x);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
fn assert(val: bool) void {
|
|
|
|
if (!val) unreachable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// run
|
|
|
|
//
|