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
})
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…