From d721d0753e0a42330a558ed1d5aec164c6880943 Mon Sep 17 00:00:00 2001 From: Dennis Brentjes Date: Tue, 5 Dec 2023 14:50:36 +0100 Subject: [PATCH] Refactor --- src/{day1/mod.rs => days/day1.rs} | 0 src/{day2/mod.rs => days/day2.rs} | 0 src/{day3/mod.rs => days/day3.rs} | 0 src/{day4/mod.rs => days/day4.rs} | 0 src/days/mod.rs | 4 ++++ src/input/mod.rs | 6 ++++-- src/main.rs | 7 +++---- 7 files changed, 11 insertions(+), 6 deletions(-) rename src/{day1/mod.rs => days/day1.rs} (100%) rename src/{day2/mod.rs => days/day2.rs} (100%) rename src/{day3/mod.rs => days/day3.rs} (100%) rename src/{day4/mod.rs => days/day4.rs} (100%) create mode 100644 src/days/mod.rs diff --git a/src/day1/mod.rs b/src/days/day1.rs similarity index 100% rename from src/day1/mod.rs rename to src/days/day1.rs diff --git a/src/day2/mod.rs b/src/days/day2.rs similarity index 100% rename from src/day2/mod.rs rename to src/days/day2.rs diff --git a/src/day3/mod.rs b/src/days/day3.rs similarity index 100% rename from src/day3/mod.rs rename to src/days/day3.rs diff --git a/src/day4/mod.rs b/src/days/day4.rs similarity index 100% rename from src/day4/mod.rs rename to src/days/day4.rs diff --git a/src/days/mod.rs b/src/days/mod.rs new file mode 100644 index 0000000..f538304 --- /dev/null +++ b/src/days/mod.rs @@ -0,0 +1,4 @@ +pub mod day1; +pub mod day2; +pub mod day3; +pub mod day4; \ No newline at end of file diff --git a/src/input/mod.rs b/src/input/mod.rs index 0f51191..f80b00c 100644 --- a/src/input/mod.rs +++ b/src/input/mod.rs @@ -1,9 +1,11 @@ -use std::{io::{BufReader, BufRead}, fs::File, str::FromStr, path::Path}; +use std::{io::{BufReader, BufRead}, fs::File, str::FromStr, path::{Path, PathBuf}}; use crate::error::AdventError; pub fn read_into_vec(file_path : &Path) -> Result, AdventError> where AdventError: From<::Err> { - let file = File::open(file_path).expect("no such file"); + let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + path.push(file_path); + let file = File::open(path).expect("no such file"); let buf = BufReader::new(file); buf.lines().map(|line| T::from_str(line?.as_str()).map_err(Into::into)).collect::, AdventError>>() } \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index ea43aac..8b859b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,9 @@ pub mod input; pub mod error; -pub mod day1; -pub mod day2; -pub mod day3; -pub mod day4; +pub mod days; + +use days::*; use std::env;