by flohofwoe · 3y ago · 0 comments
I really wonder how that decision making progress looked like :)
But it's not, hence the aforementioned bikeshedding. When Rust enum variants have data, they're like C unions with automatically-inserted tag checking. When Rust enums don't have data, they're like C enums (they're literally how you do FFI interop with enums in C, which should demonstrate beyond a shadow of a doubt that `enum` isn't categorically wrong). They have the properties of both depending on how they're defined, but at the end of the day they technically have more in common with C enums than C unions (which is why Rust also has `union` for doing C FFI).
> to get C++ programmers on board, wouldn't the obvious name not be "variant"?
Most early Rust contributors were also C++ programmers (due to Mozilla), and I don't recall a single person ever suggesting `variant` as the keyword. I suspect people here are overestimating the mindshare of boost::variant as of 2014.
Why not call Enum Union, and the FFI one CUnion or something? Like, is there something meaningful that Union is for other than C interop? Isn't it functionally identical to a tagged union in every other respect?
No :)
> is there something meaningful that Union is for other than C interop?
Look more closely at the Rust standard library, MaybeUninit<T> is a union.
The use of "enum" in Rust predates the standardization of C++17, where std::variant was introduced.
https://www.boost.org/doc/libs/1_64_0/doc/html/variant.html
The name and concept was also common enough to that I used "Variant" in my own C++ utility class collection around 2005 or so.
"OK, let's not go with that then"
"C calls it union"
"OK, we DEFINITELY can't call it that"