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