News for hackers. Stuff that matters.
Re:Using enums to represent state in Rust by Arnavion on Friday September 22, 2023 @12:04PM (#37613771)
That would still be technically misleading, since enums don't necessarily have tags due to niche optimization. Eg `Option` is an enum but `Option<Box<Foo>>` does not have any tags; it uses the content being zero to represent None since `Box<Foo>` cannot be zero.

Also, Rust does have actual tagged unions for C interop that you have to define yourself as a `struct` with an int field and a `union` field, just like in C.

Re:Using enums to represent state in Rust by twic on Friday September 22, 2023 @01:43PM (#37615126)
Rust enums always have a discriminant: https://doc.rust-lang.org/std/mem/fn.discriminant.html

Their representation in memory may not use it, but it's still defined.

Re:Using enums to represent state in Rust by 0x457 on Friday September 22, 2023 @02:37PM (#37615902)
They do, but IIRC this mostly to compare enum variants when it can't implement `Eq` and/or `PartialEq`. For example, in tests.

There are also zero variants enums that don't have any discriminant, but still could be used.

I'm not sure what's the point of comparing it to C because enums in C only carry tags and no data, while unions only carry data and no tag. Enums in rust could do both.