3 ms·
Sometimes you don't want to use `?` though, not every function is made to return a Result / Option.
by oxff 4y ago
Sometimes you don't want to use `?` though, not every function is made to return a Result / Option.
- dymk 4y agoIn 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) [0] - https://github.com/rust-lang/rust/issues/84277 https://github.com/rust-lang/rust/issues/84277
- mcronce 4y agoIf 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.