diff options
author | Irene Knapp <ireneista@gmail.com> | 2020-12-02 20:50:05 -0800 |
---|---|---|
committer | Irene Knapp <ireneista@gmail.com> | 2020-12-02 20:50:05 -0800 |
commit | 217a60c017cf54226653321c8cb5a0f844b2101d (patch) | |
tree | 304ff83605ee9d5d15fcd4377f2b82bc7cc48bdb /lib | |
parent | 55e038a16ff2a142c2144850c5bbf1ea8b5cc473 (diff) |
Day 2
Diffstat (limited to 'lib')
-rw-r--r-- | lib/src/lib.rs | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/src/lib.rs b/lib/src/lib.rs index 4b4b679..4913cbb 100644 --- a/lib/src/lib.rs +++ b/lib/src/lib.rs @@ -14,6 +14,29 @@ pub fn greeting() -> Result<()> { Ok(()) } +pub fn read_lines_file(filename: &str) -> Result<Vec<String>> { + let file = File::open(filename)?; + let mut reader = BufReader::new(file); + let mut buffer = String::new(); + + let mut input: Vec<String> = Vec::new(); + loop { + reader.read_line(&mut buffer)?; + if buffer.len() == 0 { + break; + } + + let mut line_copy = String::new(); + line_copy.push_str(buffer.trim()); + input.push(line_copy); + + buffer.clear(); + } + + Ok(input) +} + + pub fn read_int_file(filename: &str) -> Result<Vec<i64>> { let file = File::open(filename)?; let mut reader = BufReader::new(file); |