fn main() {
let inp_str = "alfa bravo charlie delta echo foxtrot golf hotel india juliett kilo lima mike november oscar papa quebec romeo sierra tango uniform victor whiskey x-ray yankee zulu";
let vowels = "aeiouy";
for word in inp_str.split_whitespace() {
let w_vec: Vec<char> = word.chars().collect();
if vowels.contains(w_vec[0]) {
let w = word.to_string().push_str("-hay");
println!("{:?}",w);
//apple-hay
} else {
//first -> irst-fay
}
}
}
result is:
eyegor@twdevel:~/devel/rust/study/exercises/chapter1/exercise2$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/exercise2`
()
()
()
()
()
()
eyegor@twdevel:~/devel/rust/study/exercises/chapter1/exercise2$
Can you describe what you actually want to achieve, please? Am I correct that you want to append -hay to each word that contains one of the letters in aeiouy?
I mean, the two versions you just posted are identical, but they are not the same as the code I posted.
Yours creates a temporary string that never gets assigned anywhere, and pushes -hay to it, and then assigns the return value of that call, which is (), or the unit value, to the variable w. Mine creates a String, assigns it to w, and pushes -hay to it. So you still have access to the string.