๐Ÿ”ข Rust Enums

Types

โ€œNormalโ€ enums:

  • Can hold enum values
    • (start at 0 without specification)
  • Can be compared (via derive)
  • Can have methods, like structs
Example:
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
enum Measure {
	Meter = 1, //optional val
	Centimeter = 2
}

// usage
Measure::Meter

Enums with data:

Mirroring struct types:

Converting

Use case