use std::{fs::File, io::{BufRead, BufReader, Lines, Read}, path::{Path, PathBuf}, str::FromStr}; use crate::error::AdventError; pub fn read_into_vec(file_path : &Path) -> Result, AdventError> where AdventError: From<::Err> { 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::, AdventError>>() } pub fn _read_into(file_path: &Path) -> Result where AdventError: From<::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())?) } pub fn get_lines(file_path: &Path) -> Lines> { 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); let lines = buf.lines(); lines }