Because it's a type-safe enumeration? ADTs are pretty much a superset of C-style enums, an ADT with all-dataless constructors is equivalent to a C enum:
enum Foo { Bar, Baz, Qux, Quux }
And members can converted to integrals:
> println!("{}", Foo::Qux as u8);
2
With explicit integrals very much like C:
> enum Foo { Bar = 5, Baz, Qux, Quux }
> println!("{}", Foo::Qux as u8);
7
Calling it "enum" makes it familiar to C developers[0], "union" would have been confusing for the same (as you can't just write one representation and read the other) and "type" is a tad too generic (and used for type aliases à la typedef).
[0] even more so C++ developers as they have `enum class` which is also type-safe and not implicitly converted to integrals
Well you are right, the name does make sense, but I would have thought "union" would have made more sense than "enum" for those of us from the C-family.
OTOH I haven't written a line of Rust of yet, so enum might be more familiar in use.
> Well you are right, the name does make sense, but I would have thought "union" would have made more sense than "enum" for those of us from the C-family.
The issue with `union` is it might hint at things which are not available (e.g. the union of an int and a float where you can access to the raw data as either).
A Rust enum is really an encoding of the `struct { enum, union }` pattern, but it degenerates to an enum if there's no union part (no data payload), not to a union. So calling it an enum makes more sense.
What Rust calls an "enum" is a discriminated variant record from Pascal. They're used in a completely different way, though. Their primary use is encapsulating function results which can be either a useful value, or some indication of error. The "Result" and "Some" generic enums are used for this. Then the "match" operation is used to fan out control depending on what enum case came back from a function. It's both elegant and kind of clunky.
Tagged unions in particular, C's version of variant types. An enum can be considered a degenerate case of such a type, so the naming isn't totally arbitrary.
Because it's a type-safe enumeration? ADTs are pretty much a superset of C-style enums, an ADT with all-dataless constructors is equivalent to a C enum:
And members can converted to integrals: With explicit integrals very much like C: Calling it "enum" makes it familiar to C developers[0], "union" would have been confusing for the same (as you can't just write one representation and read the other) and "type" is a tad too generic (and used for type aliases à la typedef).[0] even more so C++ developers as they have `enum class` which is also type-safe and not implicitly converted to integrals