Refactor
This commit is contained in:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user