Refactor
This commit is contained in:
parent
3b737d4cef
commit
d721d0753e
4
src/days/mod.rs
Normal file
4
src/days/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
pub mod day1;
|
||||
pub mod day2;
|
||||
pub mod day3;
|
||||
pub mod day4;
|
@ -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<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);
|
||||
buf.lines().map(|line| T::from_str(line?.as_str()).map_err(Into::into)).collect::<Result<Vec<T>, AdventError>>()
|
||||
}
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user