|
|
|
|
|
by masklinn
4067 days ago
|
|
> That said I wonder why they named it enum. 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 |
|
OTOH I haven't written a line of Rust of yet, so enum might be more familiar in use.