The end of file thing ‒ if you passed non-zero-sized buffer, 0 always means EOF. There are very weird things that can have EOF in the middle (like unix named pipes, where EOF means end of one „connection“, but another „connection“ might come later), but in general you want to handle that situation in the same way ‒ just stop reading.
All the „usual“ things are Read ‒ files, stdin, TcpSocket, etc, etc. Some more things are too (byte slices, decompression wrappers).
read corresponds to the OS
read syscall, with all the properties. Unless it’s something that is not a file, of course.
If you haven’t put the thing into non-blocking mode, then it’s blocking.
So if you want to do the usual „blocking“ implementation, just expect to get a blocking
Read and propagate any errors from there. If you want to handle non-blocking as well, you’ll want to implement
futures::Stream, not an Iterator and return
NotReady when you get „would block“ error.
By the way, the
read method is pretty low level thing ‒ there’s bunch of other ones (read_to_end, read_exact, …) that are much more convenient and they handle all the corner cases. Also, you might want to use
BufRead ‒ that provides few more methods and can be created from arbitrary
Read implementation by wrapping it into