diff options
| author | ivarlovlie <git@ivarlovlie.no> | 2022-12-21 15:56:24 +0100 |
|---|---|---|
| committer | ivarlovlie <git@ivarlovlie.no> | 2022-12-21 15:56:24 +0100 |
| commit | 0e1bf83811c4a9e4e2869190cfc94bf32476b9ee (patch) | |
| tree | fd518a91cc92f756dc9b8959762f7553533ce60e /rust-cli/grrs/src/lib.rs | |
| parent | 87ee550abea331430fc2db0f1d96d6acbfa6c8f2 (diff) | |
| download | learning-rust-0e1bf83811c4a9e4e2869190cfc94bf32476b9ee.tar.xz learning-rust-0e1bf83811c4a9e4e2869190cfc94bf32476b9ee.zip | |
12/21/22 15:56:24
Diffstat (limited to 'rust-cli/grrs/src/lib.rs')
| -rw-r--r-- | rust-cli/grrs/src/lib.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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<Vec<String>, Error> { + let reader = BufReader::new(file); + let mut result = Vec::<String>::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 |
