by Cyph0n · 4y ago · 0 comments
if res.is_err() {
// Do something
return;
}
let res = res.unwrap();``` let val = match res { Err(e) => { ... return ...; } Ok(v) => v, }; // Use val without unwrapping here. ```
That said, even though I'd avoid unwrap in this particular case in my code, I generally disagree with the author.
Taking out unwrap and leaving in expect would simply lead to a bunch of code that goes `let val = result.expect("!");`, which is equivalently bad when held up against the criticisms the author makes of unwrap.
Unwrap isn't really harmful so much as a symptom and an escape valve around the fact that our type systems really aren't powerful enough to derive all the invariants the programmer can about their code.