diff --git a/src/lib.rs b/src/lib.rs index 7deb460..47d1240 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,15 +53,10 @@ pub fn run(config: Config) -> Result<(), Box> { } pub fn search<'a>(query: &'a str, contents: &'a str) -> Vec<&'a str> { - let mut results = Vec::new(); - - for line in contents.lines() { - if line.contains(query) { - results.push(line); - } - } - - results + contents + .lines() + .filter(|line| line.contains(query)) + .collect() } pub fn search_case_insensitive<'a>(query: &'a str, contents: &'a str) -> Vec<&'a str> {