Enums
Enums are a simple, unparameterizable logic type that contain a list of variants, each with a specified numeric value. In the future, automatic value determination may be supported. Enums support equality and inequality operators, and assignments from other values of the same enum type. See unions for a Rust-like enum type, known as a tagged union or sum type.
Definition
Enums are defined like so:
neo
enum MyEnum {
A = 0,
B = 1,
C = 2,
}
Use
From the above example, MyEnum
becomes a valid logic type and can be instantiated:
neo
logic my_enum_val: MyEnum;
You can check enum values with the equality operator:
neo
if my_enum_val == MyEnum.A {
// ...
}
Or a case expression can be used to cover multiple variants:
neo
case my_enum_val {
.A => {
// ...
}
.B => {
// ...
}
.C => {
// ...
}
}