use std::{ fs::File, io::{self, prelude::*}, }; pub struct BufReader { reader: io::BufReader, } impl BufReader { pub fn open(path: impl AsRef) -> io::Result { let file = File::open(path)?; let reader = io::BufReader::new(file); Ok(Self { reader }) } pub fn read_line<'buf>( &mut self, buffer: &'buf mut String, ) -> Option> { buffer.clear(); self.reader .read_line(buffer) .map(|u| if u == 0 { None } else { Some(buffer) }) .transpose() } }