if_chain
if_chain copied to clipboard
Support while let
I would find it useful for if_chain to also support while let
.
if_chain! {
if let Some(b) = a;
while let Ok(c) = b;
if let Some(d) = c;
then {
do_something_with_d(d);
}
}
becomes:
if let Some(b) = a {
while let Ok(c) = b {
if let Some(d) = c {
do_something_with_d(d);
}
}
}
I'm not sure how/if this should work with the else block. Perhaps something like the following could be done.
if_chain! {
if let Some(b) = a;
while let Ok(c) = b;
if let Some(d) = c;
then {
do_something_with_d(d);
} else {
do_something_else();
}
}
becomes:
if let Some(b) = a {
let mut __executed = false;
while let Ok(c) = b {
__executed = true;
if let Some(d) = c {
do_something_with_d(d);
} else {
do_something_else();
}
}
if !__executed {
do_something_else();
}
} else {
do_something_else();
}