Pig Latin Application in rust Just finished an exercise in the Rust online book and I wanted to know if there is anything worth talking about in the code I wrote... if there's any mistake or optimization possible.
Convert strings to pig latin

The first consonant of each word is moved to the end of the word and
“ay” is added, so “first” becomes “irst-fay”.

Words that start with
a vowel have “hay” added to the end instead (“apple” becomes
“apple-hay”).

Keep in mind the details about UTF-8 encoding!


use std::io;
fn main() {
    let mut user_input = String::new();
    io::stdin()
        .read_line(&amp;mut user_input)
        .expect(&quot;Failed to read line.&quot;);
    for word in user_input.split_whitespace() {
        match word.chars().nth(0).unwrap() {
            'a' | 'e' | 'i' | 'o' | 'u' | 'y' =&gt; print!(&quot;{} &quot;, format!(&quot;{}-hay&quot;, word.trim())),
            _ =&gt; print!(&quot;{} &quot;, format!(&quot;{}{}-ay&quot;, &amp;word[word.chars().next().unwrap().len_utf8()..].trim(), word.chars().nth(0).unwrap())),
        };
    }
    println!();
}
Some small remarks:

according to the documentation, you want to output irst-fay on first, but your code will output irstf-ay instead

your code will only work on lower case words, but not on &quot;Apple&quot;

instead of print!(&quot;{} &quot;, format!(...)) use print!(...)

instead of nth(0) use next()

I recommend you to format your code with rustfmt

instead of &amp;word[word.chars().next().unwrap().len_utf8()..] you can use c.len_utf8() if you name your match instead of using _, e.g.
match word.chars().nth(0).unwrap() {
     'a' | 'e' | 'i' | 'o' | 'u' | 'y' =&gt; print!(&quot;{}-hay &quot;, word.trim())),
      c =&gt; print!(&quot;{}-{}ay &quot;, &amp;word[c.len_utf8()..].trim(), c),
};


if you know that your index will end up at a proper UTF8 boundary you can use &amp;word[1..] and &amp;word[..1] instead of your indexing, but your variant is a lot safer. Well done here, as invalid string slicing is a common error in first Rust experiences :)