4 ms·
It's a tagged union. Sometimes the tag can be elided, sometimes not. If you did a direct cast, you'd lose the tag. More specifically though, layout is undefined
by steveklabnik 11y ago
It's a tagged union. Sometimes the tag can be elided, sometimes not. If you did a direct cast, you'd lose the tag. More specifically though, layout is undefined, so you don't know if the tag is first or last, strictly speaking.
Lints for unwrap already exist :)
- lmm 11y ago> It's a tagged union. Sometimes the tag can be elided, sometimes not. If you did a direct cast, you'd lose the tag. More specifically though, layout is undefined, so you don't know if the tag is first or last, strictly speaking. Do you not have a generic syntax for unwrapping a tagged union, forcibly assuming that it's one particular component? That seems like something users would want.
- steveklabnik 11y agoThat is exactly what unwrap() is... (More specifically, it's a method which uses `match` internally to do this)
- lmm 11y agoOk, so I'm advocating forcing users to always use match directly if they want to do that. That helps ensure unsafe code looks unsafe.
- tatterdemalion 11y agoMaybe your issue is that the `get` method in Java sounds pretty innocuous, but in Rust the `unwrap` method is notorious. Every Rust user knows that it can panic. Requiring a match would increase verbosity and decrease clarity.
- pcwalton 11y agoWhy add a language feature when a library feature does the same thing?
- ben0x539 11y agoHey, it worked for try!()/?