I have a function that shouldn't return a result, but can possibly return an error, so I have the return type as Result<(), Box<dyn error::Error>>
. The functions my function calls have return types like Result<T, Err1>
and Option<V>
. I want to minimize the amount of lines dealing with error handling. Here is an example of how I'm currently doing this:
match match some_function_returning_an_Option() {
Some(x) => x,
None => return Err(MyError.into()),
}
.some_function_a()
.some_function_returning_a_Result()
{
Ok(x) => x,
Err(e) => return Err(e.into()),
}
.some_function_b()
I'm new to Rust and I'm wondering if there is a more idiomatic way of doing this.