Unpack Nested Results
Category: Rust
Warning
Result::flatten currently is unstable and requires the nightly version of Rust to run.
Context
Nested Results can quickly become an issue in Rust. Rust has neither Exceptions nor Errors. Instead, Rust has its enum Result, which is basically an Either type that either contains a success case or an error case. But due to this, sometimes, you have to deal with nested Results. In this case, your code can quickly become pretty bloated.
You can go from this:
to this:
Or from this:
to this: