grrs_tutorial/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 // This returns a Result, in case of the writing failing.
5 // And the tutorial tells us that!
6 let result = writeln!(writer, "{}", line);
7
8 match result {
9 // Should this pass additional data?
10 Err(_) => {
11 println!("Buffer writing error encountered");
12 return
13 },
14 _ => {}
15 }
16 }
17 }
18}