Detecting EOF in a Read object without consuming


I have a project where I currently read the entire input into a Vec<u8>. While this isn’t very memory efficient, one operation that is quite easy to do is checking for EOF without consuming any data. I have an index into the vector, and I can just check whether index >= buf.len().

In order to not have to read an entire file in memory, I’d like to switch to using a Read object instead. One difficulty I have is the absence of a method to check for EOF. For instance, I have a loop that looks like this:

        while !self.eof() {
            let t = self.disk_log_term()?;

(self.eof() does the check I described in the first paragraph.)

Is there a method or a trait that I missed that would give me what I’m looking for?


sounds like you are looking for std::io::BufRead::fill_buf().