I have a while let that iterates through the Result iterator and uses pattern matching; it iterates over the iterator until it hits the Err or Ok value, this is an empty string:
while let Some(Ok(a)) = some_iterator.next() { if a == "" { break; }
This code is working fine. However, I think the if looks ugly and probably not idiomatic Rust. In match statements, guards can be used when matching with a pattern, for example:
match foo { Some(Ok(a)) if a != "" => bar(a)
This would be ideal for my while let , although the pattern matching used there does not seem to support it, causing a syntax error:
while let Some(Ok(a)) = some_iterator.next() if a != "" {
Is there any way to use the guards in while let state? If not, is there a better way to exit the loop if an empty string is found?
source share