I really wonder how that decision making progress looked like :)
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.
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.
"OK, let's not go with that then"
"C calls it union"
"OK, we DEFINITELY can't call it that"
"Enum" is not the worst term here. In fact you are enumerating the variants. It's only slightly misleading. It implies that you're comparing an integer.
There is an actual enum backing it to encode the choice (tag), and a union to encode the data (if it has data). Or at least that's what I would expect.
"Variant" is used in Rust lingo to name the variants, not the whole type.
Better names would be "tagged union" (which is spot-on descriptive - because it *is* a union with a tag slapped on - but "tagged_union" of course is a bit unwieldy as keyword) or "variant" (which is the name for that thing in C++ and elsewhere since forever - it's not like Rust invented those tagged-union-thingies, it just added some convenient syntax sugar to the language to deal with them).
` (* enum ) type 'a Option = Some of 'a | None `
( struct - well: record. *) type Company = { Name : string Age : int }
Fudge. No idea how to format that in HN.