grrs_from_allen/lib.rs
1use anyhow::Result;
2
3pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) -> Result<()> {
4 for line in content.lines() {
5 if line.contains(pattern) {
6 writeln!(writer, "{}", line)?;
7 }
8 }
9 Ok(())
10}
11
12#[cfg(test)]
13mod tests {
14 use super::*;
15
16 #[test]
17 fn find_a_match() {
18 let mut result = Vec::new();
19 find_matches("Hello,\n world!", "world", &mut result).unwrap();
20 assert_eq!(result, b" world!\n");
21 }
22}