3 ms·
A Rust "enum" is in reality a tagged union; what features are you looking for there that are lacking?
by b3morales 4y ago
A Rust "enum" is in reality a tagged union; what features are you looking for there that are lacking?
- Kukumber 4y ago`unsafe` https://doc.rust-lang.org/reference/items/unions.html https://doc.rust-lang.org/reference/items/unions.html Therefore it doesn't exist in Rust
- vore 4y agoIf you need a safe tagged union, you should be using enum: https://doc.rust-lang.org/reference/items/enumerations.html https://doc.rust-lang.org/reference/items/enumerations.html Unsafe unions are for the C-style type-punning unions, which are intrinsically unsafe.
- Kukumber 4y agoThanks
- ameliaquining 4y ago"Tagged union" is a generic non-language-specific term that people who study programming languages use to refer to the language feature that Rust calls "enum". Other languages use different terms to refer to the same concept. The feature that Rust calls "union" is not a tagged union; it is an untagged union like in C (and exists primarily for the sake of compatibility with C code).