a shorter form?
let a = if let Some(b) = &c {
if let Some(d) = b.e {
calcSome(d)
} else {
0
}
} else {
0
};
So it would become one else instead of two
if the type of b is B, you can destruct it like this: if let Some(B {e: Some(d), ..}) = &c { calcSome(d) } else {0}
(&c) .and_then(|b| b.e.map(calcSome)) .unwrap_or(0)
Обсуждают сегодня