AoC-2023/src/input/mod.rs
2023-12-02 00:39:37 +01:00

16 lines
499 B
Rust

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>>()
}