4 ms·
Usually, .unwrap_or_else(|e| { fail!("well, that's unexpected") }) You need to handle all results in Rust (because the second option is the error case), or
by Argorak 12y ago
Usually,
.unwrap_or_else(|e| { fail!("well, that's unexpected") })
You need to handle all results in Rust (because the second option is the error case), or the linter will complain. Considering that failing the task (like in e.g. Erlang) is the standard way to handle errors, yes, this is somewhat idiomatic.
- dbaupp 12y agoFailing the task isn't the standard way to handle errors; propagating information via the Result type (especially the try! macro) is more conventional, as it allows the caller to handle the problem, failing is very annoying to recover from. - http://doc.rust-lang.org/nightly/std/result/ http://doc.rust-lang.org/nightly/std/result/ - http://doc.rust-lang.org/nightly/std/result/#the-try!-macro http://doc.rust-lang.org/nightly/std/result/#the-try!-macro
- Argorak 12y agoI didn't make that clear enough: I should have qualified by "if the error is indeed fatal at that point". In the example script, it really doesn't make sense to go on after that.