2 ms·
Rust enums always have a discriminant: https://doc.rust-lang.org/std/mem/fn.discriminant.html https://doc.rust-lang.org/std/mem/fn.discriminant.html Their repr
by twic 3y ago
Rust enums always have a discriminant: https://doc.rust-lang.org/std/mem/fn.discriminant.html https://doc.rust-lang.org/std/mem/fn.discriminant.html
Their representation in memory may not use it, but it's still defined.
- 0x457 3y agoThey do, but IIRC this mostly to compare enum variants when it can't implement `Eq` and/or `PartialEq`. For example, in tests. There are also zero variants enums that don't have any discriminant, but still could be used. I'm not sure what's the point of comparing it to C because enums in C only carry tags and no data, while unions only carry data and no tag. Enums in rust could do both.