I have a function, that returns Option<Result<X, String>>
and it calls some functions that return Result<Y, String>
. How is it possible to use the ?
operator in a way, that it wraps the error in a Some
?
fn other_func() -> Result<Y, String> {
// ...
}
fn my_func() -> Option<Result<X, String>> {
// ...
let value = other_func()?;
// ...
}
I have two problems:
- I do not know how to wrap
?
inSome
Result<X, String>
is different fromResult<Y, String>
, but since I only care about the error at that point, it should not matter
I am able to solve it with combining match and return, but I would like to use ?
if it is possible somehow. This is my current solution:
let value = match other_func() {
Ok(value) => value,
Err(msg) => return Some(Err(msg))
};