rust-lang/rust — pull request #18289 by mahkoh (2014-10-24 21:17:03+00:00)
Title: Specify that Reader::read doesn't return 0.

Reader is a trait for byte-oriented streams. Unlike with packet oriented
protocols such as UDP or lower level network traffic, there is no reason
for a read on a stream to ever return a zero bytes buffer.

If data is available, read shall return a suitable amount of it in the
buffer. If no data is available, read shall either block or signal a
condition via an Error.

Note that it is already impossible to use many Reader methods on packet
oriented protocols. E.g., consider reading an u64.
1) If a new packet is available, what should be done with the remainder
of the packet?
2) If we've stored a previous packet and there are still four bytes
available, should we a) attempt to read another packet and possibly
block and then combine the bytes into an 8 byte sequence, or b) return
an error?

Objects that implement packet oriented protocols or for which it makes
sense to return 0-sized reads should implement read methods that are
independent of the Reader trait.

This is a breaking change because there might be Reader implementations
that return 0, however, no such implementations are in the standard
library.

[breaking-change]

------

Note that the last paragraph is AFAIK true after https://github.com/rust-lang/rust/pull/18130

Closes https://github.com/rust-lang/rust/issues/18079