Added day 4

This commit is contained in:
Dennis Brentjes
2023-12-05 12:27:14 +01:00
parent 4a94c602f6
commit f0370944d3
2 changed files with 50 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
use std::{io::{BufReader, BufRead, self}, fs::File, str::FromStr, path::Path, convert::Infallible, num::ParseIntError};
use std::{io::{BufReader, BufRead, self}, fs::File, str::FromStr, path::Path, convert::Infallible, num::{ParseIntError, TryFromIntError}};
#[derive(Debug)]
pub struct AdventError(pub String);
@@ -21,6 +21,12 @@ impl From<Infallible> for AdventError {
}
}
impl From<TryFromIntError> for AdventError {
fn from(e: TryFromIntError) -> Self {
AdventError(e.to_string())
}
}
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 buf = BufReader::new(file);