Store config in a struct

This commit is contained in:
Manuel Thalmann 2025-03-05 08:20:57 +01:00
parent 98ce496e78
commit 7173962fe3

View file

@ -4,20 +4,25 @@ use std::fs;
fn main() { fn main() {
let args: Vec<String> = env::args().collect(); let args: Vec<String> = env::args().collect();
let (query, file_path) = parse_config(&args); let config = parse_config(&args);
println!("Searching for {query}"); println!("Searching for {}", config.query);
println!("In file {file_path}"); 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"); .expect("Should have been able to read the file");
println!("With text:\n{contents}"); println!("With text:\n{contents}");
} }
fn parse_config(args: &[String]) -> (&str, &str) { struct Config {
let query = &args[1]; query: String,
let file_path = &args[2]; file_path: String,
}
(query, file_path)
fn parse_config(args: &[String]) -> Config {
let query = args[1].clone();
let file_path = args[2].clone();
Config { query, file_path }
} }