Skip to content

Commit

Permalink
created constructor for config to parse args maintaining standards of…
Browse files Browse the repository at this point in the history
… rust
  • Loading branch information
dhanushrajgp committed Jul 6, 2024
1 parent 1090ccd commit 4caa0d5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fn main() {
println!("Hello, world!");
let args: Vec<String> = env::args().collect();

let config = parse_config(&args);
let config = Config::new(&args);

println!("Searching for {}", config.query);
println!("In file {}", config.file_path);
Expand All @@ -20,8 +20,10 @@ struct Config {
file_path: String,
}

fn parse_config(args: &[String]) -> Config {
let query = args[1].clone();
let file_path = args[2].clone();
Config { query, file_path }
impl Config {
fn new(args: &[String]) -> Config {
let query = args[1].clone();
let file_path = args[2].clone();
Config { query, file_path }
}
}

0 comments on commit 4caa0d5

Please sign in to comment.