This commit is contained in:
Dennis Brentjes 2023-12-05 14:50:36 +01:00
parent 3b737d4cef
commit d721d0753e
7 changed files with 11 additions and 6 deletions

4
src/days/mod.rs Normal file
View File

@ -0,0 +1,4 @@
pub mod day1;
pub mod day2;
pub mod day3;
pub mod day4;

View File

@ -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; use crate::error::AdventError;
pub fn read_into_vec<T:FromStr>(file_path : &Path) -> Result<Vec<T>, AdventError> where AdventError: From<<T as FromStr>::Err> { pub fn read_into_vec<T:FromStr>(file_path : &Path) -> Result<Vec<T>, AdventError> where AdventError: From<<T as FromStr>::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); let buf = BufReader::new(file);
buf.lines().map(|line| T::from_str(line?.as_str()).map_err(Into::into)).collect::<Result<Vec<T>, AdventError>>() buf.lines().map(|line| T::from_str(line?.as_str()).map_err(Into::into)).collect::<Result<Vec<T>, AdventError>>()
} }

View File

@ -1,10 +1,9 @@
pub mod input; pub mod input;
pub mod error; pub mod error;
pub mod day1; pub mod days;
pub mod day2;
pub mod day3; use days::*;
pub mod day4;
use std::env; use std::env;