or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing
xxxxxxxxxx
Rust Study Session #11
Ch. 12 (part 1): Building a Command Line Program
2020.10.16 - Salvatore La Bua
I/O Project: Implementing grep
Summary
Command Line Arguments
Creating the project
Command line call example
Reading the Argument Values
※ For invalid unicode, use std::env::args_os instead.
Reading the Argument Values
Running the program without arguments
Running the program with two arguments
Saving the Argument Values in Variables
Running the program
Reading a File
Test file
Reading a File
The code to read a file from disk
Reading a file
Running the program
Refactoring
Improve modularity
Error handling
Separating functionalities
When more functions are being added to the main program:
Split program into main.rs and lib.rs.
Separating functionalities
Applying the separation
Grouping configuration variables
Creating a structure for the configuration
Grouping configuration variables
Creating a constructor for Config
Error handling
Customise error messages
Error handling
Customise error messages
Error handling
Customise error messages
Error handling
Returning a Result
Error handling
Calling Config::new
Separating functionalities
Extracting logic from main
Error handling
Returning Errors from the run Function
Error handling
Returning Errors from the run Function
Error handling
Errors returned from run to main
Separating functionalities
Splitting code into a library crate
Move the code that is not in the main function to lib.rs:
Separating functionalities
The library crate src/lib.rs
Separating functionalities
Importing the library crate into main.rs
References
From The Rust Programming Language book:
Building a Command Line Program [EN] [JP]