Re:Rust for JavaScript Developers – Pattern Matching and Enums
by jsf01 on Sunday July 12, 2020 @02:33PM
(#23813569)
What is the reason for using different syntax for Move and TakePhoto from the Operation enum in the penultimate example? Is there a name for each of those enum member types?
[ Parent
| on HN ]
Re:Rust for JavaScript Developers – Pattern Matching and Enums
by estebank on Sunday July 12, 2020 @02:37PM
(#23813613)
Enums have 3 different variant types:
enum Foo {
StructVariant { named: i32, fields: String, with: (), types: usize },
TupleVariant(i32, String, usize), // only types and position information
UnitVariant, // just a tag, no other days being carried
}
The struct variant is useful when you are carrying enough different fields that you want to name them.