rust-unofficial / patterns

A catalogue of Rust design patterns, anti-patterns and idioms
https://rust-unofficial.github.io/patterns/
Mozilla Public License 2.0
8.02k stars 366 forks source link

Is this example wrong ? #349

Closed steinemann closed 1 year ago

steinemann commented 1 year ago

I saw the example on https://github.com/rust-unofficial/patterns/blob/main/idioms/coercion-arguments.md

fn three_vowels(word: &str) -> bool {
    let mut vowel_count = 0;
    for c in word.chars() {
        match c {
            'a' | 'e' | 'i' | 'o' | 'u' => {
                vowel_count += 1;
                if vowel_count >= 3 {
                    return true
                }
            }
            _ => vowel_count = 0
        }
    }
    false
}

Isn't _ => vowel_count = 0 wrong ? Shouldn't it just do nothing instead of resetting the vowel_count to 0 every time when a non-vowel character is found ?

steinemann commented 1 year ago

Never mind.... I have should read the text beforehand.