mirror of
https://github.com/rust-lang-cn/book-cn.git
synced 2025-02-03 07:48:41 +08:00
Start code for the I/O project chapter
This commit is contained in:
parent
ad2fc2bcf0
commit
4559876018
@ -55,7 +55,7 @@
|
||||
- [Running tests](ch11-02-running-tests.md)
|
||||
- [Test Organization](ch11-03-test-organization.md)
|
||||
|
||||
- [I/O]()
|
||||
- [An I/O Project](ch12-00-an-io-project.md)
|
||||
- [`Read` & `Write`]()
|
||||
- [`std::fs`]()
|
||||
- [`std::path`]()
|
||||
|
35
src/ch12-00-an-io-project.md
Normal file
35
src/ch12-00-an-io-project.md
Normal file
@ -0,0 +1,35 @@
|
||||
# An I/O Project
|
||||
|
||||
`cargo new --bin greprs`
|
||||
|
||||
Project requirements:
|
||||
|
||||
- Take a search string and a filename as command line arguments
|
||||
- Read the file
|
||||
- Find lines in the file that contain the search string
|
||||
- Print out those lines
|
||||
|
||||
In order to do a good job, we will:
|
||||
|
||||
- Organize code (using what we learned in modules, ch 7)
|
||||
- Use strings (collections, ch 8)
|
||||
- Handle errors (ch 9)
|
||||
- Have tests (ch 11)
|
||||
|
||||
Generics/traits/lifetimes?
|
||||
|
||||
## Command line arguments
|
||||
|
||||
* Use `std::env::args()`
|
||||
|
||||
Filename: src/main.rs
|
||||
|
||||
```rust
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
println!("{:?}", args);
|
||||
}
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user