1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
pub fn find_matches<'a>(
lines: impl Iterator<Item = String> + 'a,
pattern: &'a str,
) -> impl Iterator<Item = String> + 'a {
lines.filter(move |line| line.contains(pattern))
}
#[cfg(test)]
mod tests {
use super::find_matches;
#[test]
fn test_find_matches() {
let lines = ["A test", "Actual content", "More content", "Another test"]
.iter()
.map(|s| s.to_string());
let results: Vec<_> = find_matches(lines, "test").collect();
assert_eq!(results, ["A test", "Another test"]);
}
}