From 0e1bf83811c4a9e4e2869190cfc94bf32476b9ee Mon Sep 17 00:00:00 2001 From: ivarlovlie Date: Wed, 21 Dec 2022 15:56:24 +0100 Subject: 12/21/22 15:56:24 --- rust-cli/grrs/src/lib.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 rust-cli/grrs/src/lib.rs (limited to 'rust-cli/grrs/src/lib.rs') diff --git a/rust-cli/grrs/src/lib.rs b/rust-cli/grrs/src/lib.rs new file mode 100644 index 0000000..f91064f --- /dev/null +++ b/rust-cli/grrs/src/lib.rs @@ -0,0 +1,13 @@ +use std::{io::{BufReader, BufRead, Error}, fs::File}; + +pub fn find_matches(file: &File, pattern: &str) -> Result, Error> { + let reader = BufReader::new(file); + let mut result = Vec::::new(); + for line in reader.lines() { + let line_val = line.unwrap(); + if line_val.contains(&pattern) { + result.push(line_val); + } + } + return Ok(result); +} \ No newline at end of file -- cgit v1.3