std.meta.intToEnum -> std.enums.fromInt

Also use an optional as the return type instead of an error code.
This commit is contained in:
wooster0
2025-05-11 17:38:16 +09:00
committed by Alex Rønne Petersen
parent a3693aae3a
commit a365971a33
9 changed files with 64 additions and 67 deletions
+4 -4
View File
@@ -19,16 +19,16 @@ test "enum to int" {
try shouldEqual(Number.Four, 4);
}
fn testIntToEnumEval(x: i32) !void {
try expect(@as(IntToEnumNumber, @enumFromInt(x)) == IntToEnumNumber.Three);
fn testEnumFromIntEval(x: i32) !void {
try expect(@as(EnumFromIntNumber, @enumFromInt(x)) == EnumFromIntNumber.Three);
}
const IntToEnumNumber = enum { Zero, One, Two, Three, Four };
const EnumFromIntNumber = enum { Zero, One, Two, Three, Four };
test "int to enum" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
try testIntToEnumEval(3);
try testEnumFromIntEval(3);
}
const ValueCount1 = enum {