From 217a60c017cf54226653321c8cb5a0f844b2101d Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 2 Dec 2020 20:50:05 -0800 Subject: Day 2 --- lib/src/lib.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') 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> { + let file = File::open(filename)?; + let mut reader = BufReader::new(file); + let mut buffer = String::new(); + + let mut input: Vec = 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> { let file = File::open(filename)?; let mut reader = BufReader::new(file); -- cgit 1.4.1