4 ms·
Couldn't you match on Err? That's how I do it with `if-let` anyway if let Error(e) = my_func() { //... Do something with e }
by cercatrova 4y ago
Couldn't you match on Err? That's how I do it with `if-let` anyway
if let Error(e) = my_func() {
//... Do something with e
}
- kibwen 4y agoYes, though that doesn't put the value of the `Ok` variant into any scope. At the end of the day, if you need maximum flexibility for whatever you're doing then you still need to reach for `match`, even if it's a bit more verbose.
- dllthomas 4y agoI mean, in all cases `if let` is for when there's nothing in other constructors that you want to talk about. That'll be every time you match on `Option<T>`, `Result<T, ()>`, or `Result<(), T>`, all of which come up at least occasionally, and will occasionally be other cases. Edited to add: I don't mean to imply that you should always use `if let` for those cases - that may be but I reserve judgement on it.
- jamincan 4y agoI think in any instance where you need to unpack every variant, `match` will almost always be the least verbose option.