I'm trying to find the index of the first vowel in a string (English/ASCII only). I need to extract this index to use it later on (returned in this example). This works:
let s = String::from("cats");
let vowels = ['a', 'e', 'i', 'o', 'u'];
for v in vowels {
let index = s.to_lowercase().find(v);
if let Some(i) = index {
return i;
}
break;
}
This works fine, but I feel like there should be a more concise way to do this. Every oneliner I try returns a bool that there was a match or an iterator in vowels rather than the index in the string, s. Help?