My first thought is to map
the Option
, but I can't use try!
from inside of the closure. The match
statement looks unnecessary, but I can't figure out how to simplify it.
fn example<T, E>(val: Option<Result<T, E>>) -> Result<Option<T>, E> {
Ok(match val {
Some(v) => Some(v?),
None => None
})
}
val.map(|v| v.map(Ok)).unwrap_or_else(|e| Some(Err(e)))
– Sada