2 ms·
It is especially confusing for C and C++ coders, because Rust enums are a completely different thing than C enums, which makes the naming choice worse than just
by flohofwoe 3y ago
It is especially confusing for C and C++ coders, because Rust enums are a completely different thing than C enums, which makes the naming choice worse than just inventing a new name.
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).
- jowea 3y agoMaybe it's because you can use a Rust enum like in C by doing a field-less or unit-only enum?
- hurril 3y agoI agree with you! I dislike the name enum and really like how F# does it. In F#, everything is type and what kind of type you create comes down to the type construction literal you use. ` (* 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.