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: Check the roster - Rust Tutorial
From the course: Rust Essential Training
Solution: Check the roster
(upbeat music) - [Presenter] My solution to the check the roster challenge starts by importing two modules from the standard library at the top. The environment module to access the command line arguments and the file system or FS module to read the input text file. Down in the main function on line five, I checked to make sure that the user passed enough arguments when they called the program. If they did not, then I print a message to politely let them know that this program requires two arguments and then return out of the main function on line seven to exit the program. If they did provide two input arguments then lines nine and 10 get those values which should represent the file path and the name to search for. The four loop online 12 uses the read to string function to read the entire contents of the file and then uses the lines method to iterate over the lines individually. Within the loop, I check each line…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.