3 ms·
Rust's enums are "sum types" or "tagged unions". Perhaps the most practical example of this is the Option type, where you can say an Optional value is either `
by rgoulter 3y ago
Rust's enums are "sum types" or "tagged unions".
Perhaps the most practical example of this is the Option type, where you can say an Optional value is either `Some(value)` or `Nothing`.
With this, you don't have do deal with null pointers; a `null` pointer would instead be `Nothing`, and a non-null value would be `Some(value)`, and the compiler can enforce you're sticking to this.
- jerf 3y agoI wish "enums" would stay relatively simple numbers or something and "sum types" would remain full sum types, but, here we are. Now whenever I see someone asking for "enums" I have to ask them what they're actually saying, because the majority of the time they mean sum types, but only the majority. It is not even close to always. Sometimes people want more fully featured enumerations, too, e.g., better automatic stringification of a variety of types.