Determine if BufRead is empty?

Is there a way to determine if a BufRead is empty without attempting to read any bytes?

I'm stuck using an API that requires me to create a reader from a BufRead, and I have to keep reading until I get an custom error type, and then match against the description of the error type to figure out whether the file is at the end or not :frowning:

I'd much prefer to just check whether the mut BufRead I passed a reference to is at the end, in the read loop, and then break.

If I understood your case, BufRead in std::io - Rust should work - if it returns an empty slice, you’re at EOF.

1 Like

Oh boy I must be tired. Very first method in the docs :stuck_out_tongue_closed_eyes:

Works perfectly, thank you!