5 ms·
Does anyone know why `union` isn't a reserved word in Rust? Most contextual keywords in other languages come from either: 1. Features that were added after th
by munificent 1y ago
Does anyone know why `union` isn't a reserved word in Rust?
Most contextual keywords in other languages come from either:
1. Features that were added after the language was in wide use and can't add keywords without breaking existing code.
2. Features where the word is particularly useful elsewhere, so would be painful to reserve (like `get` and `set` in Dart).
But neither of those seem to apply to Rust. As far as I know, it's always had ML-style unions, and "union" doesn't seem to be a particularly useful identifier otherwise.
Why isn't `union` fully reserved?
- steveklabnik 1y agoIt's simply that Rust has higher standards for breaking changes than "probably not in wide use." In other words, that someone could have had `let union =`... somewhere was a reason to make it contextual. https://rust-lang.github.io/rfcs/1444-union.html#contextual-keyword https://rust-lang.github.io/rfcs/1444-union.html#contextual-...
- munificent 1y agoOoooooh, I see my confusion now. My brain switched off and I got enums and unions confused. I was like, wait, hasn't Rust had them since day one? I was thinking of `enum`, not `union`. My bad.
- steveklabnik 1y agoAhhh yeah, no worries!
- pitaj 1y agoIt's a common operation on sets, so would make `HashSet::union` [1] and friends less obvious, for no real benefit. [1] https://doc.rust-lang.org/stable/std/collections/struct.HashSet.html#method.union https://doc.rust-lang.org/stable/std/collections/struct.Hash...