@@ -300,12 +300,25 @@ impl<E: fmt::Debug> std::error::Error for WriteFmtError<E> {}
300300pub trait Read : ErrorType {
301301 /// Read some bytes from this source into the specified buffer, returning how many bytes were read.
302302 ///
303- /// If no bytes are currently available to read, this function blocks until at least one byte is available.
303+ /// If no bytes are currently available to read:
304+ /// - The method blocks until at least one byte becomes available;
305+ /// - Once at least one (or more) bytes become available, a non-zero amount of those is copied to the
306+ /// beginning of `buf`, and the amount is returned, *without waiting or blocking any further for
307+ /// more bytes to become available*.
308+ ///
309+ /// If bytes are available to read:
310+ /// - A non-zero amount of bytes is read to the beginning of `buf`, and the amount is returned immediately,
311+ /// *without blocking and waiting for more bytes to become available*;
312+ ///
313+ /// Note that once some bytes are available to read, it is *not* guaranteed that all available bytes are returned.
314+ /// It is possible for the implementation to read an amount of bytes less than `buf.len()` while there are more
315+ /// bytes immediately available.
304316 ///
305- /// If bytes are available, a non-zero amount of bytes is read to the beginning of `buf`, and the amount
306- /// is returned. It is not guaranteed that *all* available bytes are returned, it is possible for the
307- /// implementation to read an amount of bytes less than `buf.len()` while there are more bytes immediately
308- /// available.
317+ /// This blocking behavior is important for the cases where `Read` represents the "read" leg of a pipe-like
318+ /// protocol (a socket, a pipe, a serial line etc.). The semantics is that the caller - by passing a non-empty
319+ /// buffer - does expect _some_ data (one or more bytes) - but _not necessarily `buf.len()` or more bytes_ -
320+ /// to become available, before the peer represented by `Read` would stop sending bytes due to
321+ /// application-specific reasons (as in the peer waiting for a response to the data it had sent so far).
309322 ///
310323 /// If the reader is at end-of-file (EOF), `Ok(0)` is returned. There is no guarantee that a reader at EOF
311324 /// will always be so in the future, for example a reader can stop being at EOF if another process appends
0 commit comments