This commit is contained in:
Dennis Brentjes
2023-12-05 12:36:28 +01:00
parent f0370944d3
commit 52db8b9109
7 changed files with 37 additions and 35 deletions

View File

@@ -1,31 +1,6 @@
use std::{io::{BufReader, BufRead, self}, fs::File, str::FromStr, path::Path, convert::Infallible, num::{ParseIntError, TryFromIntError}};
use std::{io::{BufReader, BufRead}, fs::File, str::FromStr, path::Path};
#[derive(Debug)]
pub struct AdventError(pub String);
impl From<ParseIntError> for AdventError {
fn from(e: ParseIntError) -> Self {
AdventError(e.to_string())
}
}
impl From<io::Error> for AdventError {
fn from(e: io::Error) -> Self {
AdventError(e.to_string())
}
}
impl From<Infallible> for AdventError {
fn from(_: Infallible) -> Self {
unreachable!()
}
}
impl From<TryFromIntError> for AdventError {
fn from(e: TryFromIntError) -> Self {
AdventError(e.to_string())
}
}
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> {
let file = File::open(file_path).expect("no such file");