diff --git a/src/lib.rs b/src/lib.rs index 57dda36..92c834b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,9 +8,9 @@ pub struct Config { } impl Config { - pub fn build(mut args: Vec) -> Result { + pub fn build(mut args: &mut Vec) -> Result { args.remove(0); // Remove program path - let ignore_case = Self::ignore_case(&mut args); + let ignore_case = Self::ignore_case(args); if args.len() < 2 { return Err("Argument not enough!"); @@ -74,7 +74,7 @@ mod tests { use super::*; - fn run_search(args: Vec) -> Vec { + fn run_search(args: &mut Vec) -> Vec { let config = Config::build(args).unwrap(); let file_content = std::fs::read_to_string(&config.file_path) @@ -87,10 +87,10 @@ mod tests { #[test] fn test_search() { - let args: Vec = vec!["target/debug/m-grep", "Who", "poem.txt"] + let mut args: Vec = vec!["target/debug/m-grep", "Who", "poem.txt"] .iter().map(|&x| x.into()).collect(); - let result = run_search(args); + let result = run_search(&mut args); for line in result { println!("{line}"); @@ -100,10 +100,10 @@ mod tests { #[test] fn test_search_ignorecase() { - let args: Vec = vec!["target/debug/m-grep", "who", "poem.txt", "-i"] + let mut args: Vec = vec!["target/debug/m-grep", "who", "poem.txt", "-i"] .iter().map(|&x| x.into()).collect(); - let result = run_search(args); + let result = run_search(&mut args); for line in result { assert_eq!(line, format!("I'm nobody! {} are you?", "Who".green())); diff --git a/src/main.rs b/src/main.rs index 5c07f8f..9514ec2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,15 +4,15 @@ use std::process; use s_grep::{Config, search}; fn main() { - let args: Vec = std::env::args().collect(); + let mut args: Vec = std::env::args().collect(); - if let Err(err) = run(args) { + if let Err(err) = run(&mut args) { eprintln!("{}: {}", "Error".red().bold(), err.to_string().red()); process::exit(1); } } -fn run(args: Vec) -> Result<(), Box> { +fn run(args: &mut Vec) -> Result<(), Box> { let config = Config::build(args)?; let file_path = &config.file_path;