From the course: Rust Essential Training

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Solution: Count words

Solution: Count words - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Solution: Count words

(upbeat music) - [Instructor] My solution to the count words challenge has four stages. So let's walk through those in sequence. The first section on lines, seven through 20 reads the input text file, and then breaks it up into a vector containing the individual words. The match expression on line seven checks to make sure the program was passed and input argument for the file to open. If it's Some, the second match expression on line eight, leads that file to a string and then the Ok match arm on line nine uses the two lowercase method to convert all the texts to lowercase. That way we can ignore capitalization when comparing words. If either of those match expressions fail, I print an error message to let the user know what went wrong and then exit the program. Line 20 takes the lowercase string of file contents and uses the split white space method, to break it up into individual words. That method returns an…

Contents