diff --git a/src/matches.rs b/src/matches.rs index 41ac4a6..322a00d 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -77,7 +77,7 @@ pub fn matches(vars: &mut Vars, env_args: &[String]) -> Result { } pub trait Match { - fn get(&self, arg: &str) -> Option; + fn get(&self, arg: &str) -> Option<&String>; fn has_match(&self, arg: &str) -> bool; @@ -85,11 +85,8 @@ pub trait Match { } impl Match for Matches { - fn get(&self, arg: &str) -> Option { - match self.get(arg) { - Some(s) => Some(s.clone()), - None => None - } + fn get(&self, arg: &str) -> Option<&String> { + self.get(arg) } fn has_match(&self, arg: &str) -> bool { @@ -118,6 +115,6 @@ mod tests { }; let argument = matches.get("a").unwrap(); - assert_eq!(argument, String::from("Test")); + assert_eq!(*argument, String::from("Test")); } } diff --git a/tests/main.rs b/tests/main.rs index 191cdd2..b1a6fc7 100644 --- a/tests/main.rs +++ b/tests/main.rs @@ -4,9 +4,10 @@ use pirate::{Matches, Match, matches, usage, vars}; #[test] fn main() { - let env_args: Vec = vec![String::from("test"), String::from("-a"), String::from("2"), String::from("3")]; + let env_args: Vec = vec![String::from("test"), String::from("-a"), String::from("2"), + String::from("3")]; let opts = vec!["a/addend(The right side of the addition equation; default=1):", "(Required Arguments)", - ":augend(The left side of an addition equation)"]; + ":augend(The left side of an addition equation)"]; let mut vars = vars("test", &opts).unwrap(); let matches: Matches = match matches(&mut vars, &env_args) {