Skip to content

Commit

Permalink
Making Code Clearer with Iterator Adaptors
Browse files Browse the repository at this point in the history
  • Loading branch information
leanndroguedes committed Jul 20, 2021
1 parent 49c156f commit cae52b2
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,10 @@ pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
}

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> {
Expand Down

0 comments on commit cae52b2

Please sign in to comment.