Feat: move find_matches to a library.

This commit is contained in:
Ian Rettig
2025-06-09 13:32:16 -04:00
parent bcb4cba5e1
commit 946f4a5466
2 changed files with 19 additions and 20 deletions
+18
View File
@@ -0,0 +1,18 @@
use anyhow::Result;
pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) -> Result<()> {
for line in content.lines() {
if line.contains(pattern) {
writeln!(writer, "{}", line)?;
}
}
Ok(())
}
#[test]
fn find_a_match() -> Result<(), Box<dyn std::error::Error>> {
let mut result = Vec::new();
find_matches("lorem ipsum\ndolar sit amet", "lorem", &mut result)?;
assert_eq!(result, b"lorem ipsum\n");
Ok(())
}