I have two structures which aren't necessary the same type but have at least 3 levels of the nesting, every field is Option. In case of just accessing the field the chain of map() or and_then() could suffice depending on the details. But it's seems (at least to me, Rust newbie) not possible to work with mutable references this way due to the lack of syntax/methods.
I want to avoid long nested chains like that:
if let Some(a) = bla.a {
if let Some(b) = a.b {
if let Some(c) = b.c {
if let Some(ref mut a1) = foo.a {
if let Some(ref mut b1) = a1.b {
if let Some(ref mut c1) = b1.c {
// Here we could perform various modifications on "c" member
// before the assignment for this operation to make sense
*c1 = some_operation(c)
}
}
}
}
}
}
#![feature(let_chains)]
if let Some(a) = bla.a
&& let Some(b) = a.b
&& let Some(c) = b.c
&& let Some(ref mut a1) = foo.a
&& let Some(ref mut b1) = a1.b
&& let Some(ref mut c1) = b1.c
{
// Here we could perform various modifications on member
// before the assignment for this operation to make sense
*c1 = c
}