2 ms·
It's all good! Yeah, Rust has C-style unions as well, though they're unsafe, and largely for C interop. Rust's enums give you the full power of putting other d
by steveklabnik 6y ago
It's all good! Yeah, Rust has C-style unions as well, though they're unsafe, and largely for C interop.
Rust's enums give you the full power of putting other data structures inside of them; the variants can hold data of any kind; single values, structs, tuples, and even other enums.
- jkarneges 6y agoComing from C/C++, "enums with data" sound more interesting to me than "unions with a type", even though they describe the same thing. I used C/C++ enums far more often than unions, and often wished I could add extra data to them. Another thing is that adding data to Rust enums is optional, and so you can have an enum of variants with no data. The union equivalent to that would be a type-only union which sounds kind of odd.