1use std::io::{self, BufReader, Write};
2use std::fs::File;
3use std::io::prelude::*;
4
5pub fn read_lines(filename: std::path::PathBuf) -> io::Result<io::Lines<BufReader<File>>> {
6 let file = File::open(filename).expect("No file found");
7 Ok(io::BufReader::new(file).lines())
8}
9
10pub fn find_matches(content: io::Lines<BufReader<File>>, pattern: String, mut writer: impl Write) {
11 for line in content {
12 if let Ok(line) = line {
13 if line.contains(&pattern) {
14 writeln!(writer, "{}", line).expect("Writer failed");
15 }
16 }
17 }
18}