This is the exercise for Week 2 of the Rust Fundamentals Course
In this lab, you will enhance a file reader application in Rust. Use the example code for error handling as a starting point for reading a file and printing its contents. You are tasked with extending the application to allow users to specify the file to be read as a command-line argument. The end result will be a GitHub repository containing the complete code for the enhanced file reader application.
Learning Objectives:
-
Understand how to read and process files in Rust using the standard library.
-
Practice error handling techniques, such as matching on different error cases.
-
Learn how to organize code and structure a Rust application.
Steps:
-
Create a new repository in your account for your Rust project. Use the Rust template repository to quickly generate one for your account .
-
Use the example code as a starting point
-
Add the ability to pass in any file path to avoid hard-coding the path in the program. Use the Rust docs or this sample code to get an idea on how to get the first argument in the console:
use std::env;
fn main() {
let args: Vec<String> = env::args().collect();
// The first argument is the path that was used to call the program.
println!("My path is {}.", args[0]);
}