pub fn read_exactish(reader: &mut impl Read, buf: &mut [u8]) -> Result<bool>Expand description
This function reads the exact amount of bytes required to fill the buffer, possibly performing multiple reads to do so (and also retrying if required to deal with EINTR).
The “-ish” is that, unlike the standard Read::read_exact() method, it’s possible to determine the difference between an incomplete read (where some amount of bytes were read, but the buffer wasn’t filled) and a “clean” EOF where an EOF occurred immediately with no data read at all, which is still considered to be a success.
§Return value
There are four possible return values:
- in case the requested number of bytes were successfully read into the buffer, returns Ok(true)
- in case of a “clean” EOF where the stream ends immediately, the function returns Ok(false)
- in case of an unexpected EOF after some bytes were read, the function returns an Error with ErrorKind::UnexpectedEof
- in case of underlying errors from the Read implementation, the error is returned directly