use crate::ShellError; use std::io::{BufRead, BufReader, Read}; pub struct BufferedReader { pub input: BufReader, } impl BufferedReader { pub fn new(input: BufReader) -> Self { Self { input } } } impl Iterator for BufferedReader { type Item = Result, ShellError>; fn next(&mut self) -> Option { let buffer = self.input.fill_buf(); match buffer { Ok(s) => { let result = s.to_vec(); let buffer_len = s.len(); if buffer_len == 0 { None } else { self.input.consume(buffer_len); Some(Ok(result)) } } Err(e) => Some(Err(ShellError::IOError { msg: e.to_string() })), } } }