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.

Command-line arguments

Command-line arguments - Rust Tutorial

From the course: Rust Essential Training

Start my 1-month free trial

Command-line arguments

- [Instructor] Command-line arguments allow us to pass information to our program when it's invoked as arguments that get passed to the main function. Command-line arguments are often used to provide the path to external files of program will need to use, or as configuration flags which tell the program to behave a certain way or operate in a specific mode. Your program will need to make sense of any arguments it gets passed to act accordingly. To read the values of command-line arguments in Rust, we use the args function which is included in the standard libraries environment module. Args will return an iterator with any command line arguments that were passed to the program when it was called. The first argument is traditionally the path to the executable itself. However, that's not guaranteed in every environment so your program should not rely on that being the case. The environment module is not included in the prelude,…

Contents