mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
std.meta.intToEnum -> std.enums.fromInt
Also use an optional as the return type instead of an error code.
This commit is contained in:
committed by
Alex Rønne Petersen
parent
a3693aae3a
commit
a365971a33
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user