rust-fundamentals

Create a File Reader Application

In this lab, you will enhance a file reader application in Rust.  Use the example code Opens in a new tab   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:

Steps:

    1. Create a new repository in your account for your Rust project. Use the Rust template repository to quickly generate one for your own account. Use this link to create it in one step.
  1. Use the example code as a starting point
  2. 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]);
}

Concepts Covered:

By completing this lab, you will gain practical experience in Rust by extending an existing file reader application. You will develop skills in file I/O, error handling, and some basic code organization, utilizing the concepts introduced in the lessons for this week.