Basic Enumerations

An enumeration, or enum in Rust, is a way to declare a custom data type that describes, or enumerates, possible variations of a certain category. In the example below, the data type is named Language, and it serves as the category for which all the named items within are a part. EnglishSpanish, etc. are all a member of the Language enumeration. Enumerations are implicitly given an integer value corresponding with their ordinal position within the definition, starting with 0. Unless expressly overridden, the numerical value of each member increments by 1. These types of enumerations are classified as unit-only enums. Other types of enumerations are described in detail in the Advanced Enumerations section.

// Unit-only enumeration
enum Language {
  English,  // = 0
  Spanish,  // = 1
  Italian,  // = 2
  French,   // = 3
  German,   // = 4
}
// Overridden unit-only enumeration
enum Country {
  America = 4,
  Germany,  // = 5
  France,   // = 6
  Austria = 8,
}