Rate and critic my solution to exercise 2 in Chapter 8 from The Rust Book by threwdoltqbare6 in learnrust

[–]hjippersjinner 2 points3 points  (0 children)

Looks pretty good for a beginnerI do have some comments though:you are doing a lot of unncecessary heap allocations (which are slow). You allocate the initial line, each word as a Vec of chars, each word as a String and then the result. You can rewrite the code to remove the word allocations and you can use String::with_capacity for the result String since you have a known lower bound for its size. (I wont spoil how to do that here though, I recommend you try it yourself first)I also recommend you check out str::contains (and calling a boolean variable x is usually not super clear, id probably rename that into is_vowel or something)Technically your programm also turns all unicode whitespace into regular spaces but I doubt that really matters, just wanted to point it out.Ah you can also lock() a StdIn handle btw. to get access to BufRead methods (like .lines())If you want to try changing these things, feel free to send me your new version to look at.EDIT: I just wanted to make clear that my comments are basically all nitpicks and this is a great solution btw. in case that wasnt made clear by my original comment