Enums

An enum is a type which values may be equal to one of named values specified in its declaration.

Enum declaration example:

enum FixedColor
{
    Black,
    White,
    Red,
    Green,
    Blue,
    Yellow,
    Magenta,
    Cyan,
};

enum Component : i16 // Underlying type is specified
{
    One,
    Two,
    Three,
};

Usage:

var FixedColor mut c= FixedColor::Black;
c= FixedColor::Red;
if( c == FixedColor::Red ) {}

Enum values may be assigned, compared, converted into an integer and used as template arguments. Result of enum to integer conversion is an integer value that is equal to the index of this enum value in the enum declaration.

It’s possible to compare enum values via ==, !=, <, <=, >, >=, <=>. One enum value is greater than other, if it is declared later.

I’s possible to specify underlying integer type for an enum. The size of enum values will be equal to the size of underlying type values. If no underlying type is specified it will be chosen automatically - u8, u16 or u32 depending on the number of possible enum values.

Enums can’t be empty - they should have at least one value. An enum may have no more values than maximum value of its underlying type.