Is there any way to express things like: while let Some(..) = .. && true
I wrote my code as below:
// some external variable: a
while let Some(&(x, y, z)) = stk.last() {
if cmp(x, a) {
stk.pop();
// do my thing ...
} else {
break;
}
}
I wish to avoid else break block, because it's not very necessary and kinda verbose.I thought it'll be nice if I can put cmp(x, a) in the same line with while let, but this is not allowed.
Extends if let and while let -expressions with chaining, allowing you to combine multiple let s and bool -typed conditions together naturally. After implementing this RFC, you'll be able to write, among other things:
...
while let Ok(user) = read_user(::std::io::stdin())
&& user.name == "Alan Turing"
&& let Ok(hobby) = read_hobby_of(&user)
{
if hobby == "Hacking Enigma" {
println!("Yep, It's you.");
return Some(read_encrypted_stuff());
} else {
println!("You can't be Alan! ");
}
}
return None;