mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-05-02 03:08:03 +08:00
35 lines
693 B
Rust
35 lines
693 B
Rust
use std::env;
|
|
use std::fs;
|
|
|
|
// ANCHOR: here
|
|
fn main() {
|
|
let args: Vec<String> = env::args().collect();
|
|
|
|
let config = parse_config(&args);
|
|
|
|
println!("Searching for {}", config.query);
|
|
println!("In file {}", config.file_path);
|
|
|
|
let contents = fs::read_to_string(config.file_path)
|
|
.expect("Should have been able to read the file");
|
|
|
|
// --snip--
|
|
// ANCHOR_END: here
|
|
|
|
println!("With text:\n{contents}");
|
|
// ANCHOR: here
|
|
}
|
|
|
|
struct Config {
|
|
query: String,
|
|
file_path: String,
|
|
}
|
|
|
|
fn parse_config(args: &[String]) -> Config {
|
|
let query = args[1].clone();
|
|
let file_path = args[2].clone();
|
|
|
|
Config { query, file_path }
|
|
}
|
|
// ANCHOR_END: here
|