takaiyuk_grrs/
lib.rs

1pub fn find_matches(content: &str, pattern: &str, mut writer: impl std::io::Write) {
2    for line in content.lines() {
3        if line.contains(pattern) {
4            if let Err(e) = writeln!(writer, "{}", line) {
5                eprintln!("Couldn't write to stdout: {}", e);
6            }
7        }
8    }
9}
10
11#[cfg(test)]
12mod tests {
13    use super::*;
14
15    #[test]
16    fn test_find_matches() {
17        let mut result = Vec::new();
18        find_matches("lorem ipsum\n", "lorem", &mut result);
19        assert_eq!(result, b"lorem ipsum\n");
20    }
21}