Initial commit.
This commit is contained in:
16
src/input/mod.rs
Normal file
16
src/input/mod.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use std::{path::Path, io::{BufReader, BufRead, self}, fs::File};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct AdventError(String);
|
||||
|
||||
impl From<io::Error> for AdventError {
|
||||
fn from(e: io::Error) -> Self {
|
||||
AdventError(e.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_into_vec(path: &Path) -> Result<Vec<String>, AdventError> {
|
||||
let file = File::open(path).expect("no such file");
|
||||
let buf = BufReader::new(file);
|
||||
buf.lines().map(|line| line.map_err(Into::into)).collect::<Result<Vec<String>, AdventError>>()
|
||||
}
|
||||
Reference in New Issue
Block a user