Any idea how to write more idiomatic Rust, a for loop with comparison

74 points eXoRainbow

Hi. I have a little construct that I don't like. It seems to work how it should, but it does not look idiomatic and little bit confusing. Is it okay in your opinion or are there "better" ways to realize that? I just post the part that is interesting for the focus.

let pattern_list: Vec<WildMatch> is created earlier from possibly multiple --filter options on the commandline. gstring is basically a string representation of a variable game Path. The idea is to compare each pattern to the path. Only if all pattern matches the string representation, it should return the original game as a Path. (Otherwise the execution continues and finds None to return.)

let mut matches = true;
for pattern in &pattern_list {
    if !pattern.matches(&gstring) {
        matches = false;
        break;
    }
}
if matches {
    return Some(game.clone());
}

As said, it works for me. But I don't like break and creating temporary variable and then a disconnected test of that variable and such. What you think?