Store config in a struct
This commit is contained in:
parent
98ce496e78
commit
7173962fe3
1 changed files with 14 additions and 9 deletions
|
@ -4,20 +4,25 @@ use std::fs;
|
|||
fn main() {
|
||||
let args: Vec<String> = env::args().collect();
|
||||
|
||||
let (query, file_path) = parse_config(&args);
|
||||
let config = parse_config(&args);
|
||||
|
||||
println!("Searching for {query}");
|
||||
println!("In file {file_path}");
|
||||
println!("Searching for {}", config.query);
|
||||
println!("In file {}", config.file_path);
|
||||
|
||||
let contents = fs::read_to_string(file_path)
|
||||
let contents = fs::read_to_string(config.file_path)
|
||||
.expect("Should have been able to read the file");
|
||||
|
||||
println!("With text:\n{contents}");
|
||||
}
|
||||
|
||||
fn parse_config(args: &[String]) -> (&str, &str) {
|
||||
let query = &args[1];
|
||||
let file_path = &args[2];
|
||||
|
||||
(query, file_path)
|
||||
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 }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue