Re:Rust should not have provided `unwrap`
by oxff on Friday July 15, 2022 @01:18PM
(#32110508)
Sometimes you don't want to use `?` though, not every function is made to return a Result / Option.
[ Parent
| on HN ]
If your function is fallible, your function is fallible - it's up to you to decide whether that means returning Result or panicking. If you want your function to be infallible, while itself calling a fallible function, you have to handle the error cases from your callees - you have `.unwrap_or_default()`, `.unwrap_or_else()`, `.unwrap_or()`, and simple `match` all in your toolbox to do this.
In that case, you use `unwrap`, or you manually convert it into your return type, or you provide an `impl Try` [0] for your return type once that feature becomes stable (already possible if you're on nightly)