2 ms·
What we're discussing here is always an actual sum type though, it's just a question of whether you're interested in half-assing it, and Rust is not. There are
by tialaramex 2y ago
What we're discussing here is always an actual sum type though, it's just a question of whether you're interested in half-assing it, and Rust is not.
There are people who want C's "surprise it's actually just an integer" which lets them use C's enums as bit flags, and that I agree isn't just a sum type, but the fact that Rust will let you sum things which aren't units isn't that this is "really" a tagged union, that's a possible implementation detail but not the core idea.
This is not C++ std::variant which really is just a tagged union. Option<OwnedFd> isn't a tagged union, it's "just" much nicer sugar for C's signed integer type. Option<&str> isn't a tagged union it's sugar for a fat pointer which can be null. And so on.