Adds Day 5 solution 1.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{io::{BufReader, BufRead}, fs::File, str::FromStr, path::{Path, PathBuf}};
|
||||
use std::{io::{BufReader, BufRead, Read}, fs::File, str::FromStr, path::{Path, PathBuf}};
|
||||
|
||||
use crate::error::AdventError;
|
||||
|
||||
@@ -8,4 +8,13 @@ pub fn read_into_vec<T:FromStr>(file_path : &Path) -> Result<Vec<T>, AdventError
|
||||
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>>()
|
||||
}
|
||||
|
||||
pub fn read_into<T:FromStr>(file_path: &Path) -> Result<T, AdventError> where AdventError: From<<T as FromStr>::Err> {
|
||||
let mut path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
||||
path.push(file_path);
|
||||
let mut file = File::open(path).expect("no such file");
|
||||
let mut str: String = "".to_string();
|
||||
file.read_to_string(&mut str)?;
|
||||
Ok(T::from_str(str.as_str())?)
|
||||
}
|
||||
Reference in New Issue
Block a user