mirror of
https://github.com/KaiserY/trpl-zh-cn
synced 2025-02-25 05:42:18 +08:00
30 lines
602 B
Rust
30 lines
602 B
Rust
|
use std::env;
|
||
|
use std::fs;
|
||
|
|
||
|
// ANCHOR: here
|
||
|
fn main() {
|
||
|
let args: Vec<String> = env::args().collect();
|
||
|
|
||
|
let (query, filename) = parse_config(&args);
|
||
|
|
||
|
// --snip--
|
||
|
// ANCHOR_END: here
|
||
|
|
||
|
println!("Searching for {}", query);
|
||
|
println!("In file {}", filename);
|
||
|
|
||
|
let contents = fs::read_to_string(filename)
|
||
|
.expect("Something went wrong reading the file");
|
||
|
|
||
|
println!("With text:\n{}", contents);
|
||
|
// ANCHOR: here
|
||
|
}
|
||
|
|
||
|
fn parse_config(args: &[String]) -> (&str, &str) {
|
||
|
let query = &args[1];
|
||
|
let filename = &args[2];
|
||
|
|
||
|
(query, filename)
|
||
|
}
|
||
|
// ANCHOR_END: here
|