Metadata
aliases: [Enum in Rust]
shorthands: {}
created: 2022-06-17 11:37:46
modified: 2022-06-17 15:38:26
Enums are special in Rust, since each variant in the enum can have different types.
For example, an arbitrary message type:
enum Message {
Quit,
Print(String),
AddElement(ElementIndex),
RemoveElement(ElementIndex),
Move {x: f64, y: f64},
}
Where the Quit variant has no type, it just carries the information of it being the variant Quit. But the other variants all have other information with in them:
Print has a StringMove has a struct representing a 2D point with coordinatesAddElement and RemoveElement varieties carry a hypothetical ElementIndex type, but it does not exist in the Rust std, it is just hypothetical