mirror of https://github.com/KaiserY/trpl-zh-cn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
35 lines
689 B
35 lines
689 B
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.filename);
|
|
|
|
let contents = fs::read_to_string(config.filename)
|
|
.expect("Something went wrong reading the file");
|
|
|
|
// --snip--
|
|
// ANCHOR_END: here
|
|
|
|
println!("With text:\n{}", contents);
|
|
// ANCHOR: here
|
|
}
|
|
|
|
struct Config {
|
|
query: String,
|
|
filename: String,
|
|
}
|
|
|
|
fn parse_config(args: &[String]) -> Config {
|
|
let query = args[1].clone();
|
|
let filename = args[2].clone();
|
|
|
|
Config { query, filename }
|
|
}
|
|
// ANCHOR_END: here
|