I'm calling a function that returns a Result<T, E>
and I want to handle the Ok
case but return the Err
as is if an error is returned. What is the cleanest way to do this?
For example, I have:
fn example() -> Result<(), Error> {
match foo() {
Ok(v) => bar(v),
Err(e) => Err(e),
}
}
What are some alternate forms of writing this? It feels weird to re-wrap e
in another Err
in every call in the stack. Also, every call is basically 4 lines of boilerplate... I'm just looking for a way to simplify and make it more readable. My desire is to have it return the error if error, else process the result value.