grrs/lib.rs
1pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) -> std::io::Result<()> {
2 for line in content.lines() {
3 if line.contains(pattern) {
4 writeln!(writer, "{}", line)?;
5 }
6 }
7 Ok(())
8}
9
10#[test]
11fn find_a_match() {
12 let mut result = Vec::new();
13 let _ = find_matches("lorem ipsum\ndolor sit amet", "lorem", &mut result);
14 assert_eq!(result, b"lorem ipsum\n");
15}
16