diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2021-05-23 03:23:37 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-23 03:23:37 +0200 |
| commit | b1e0d5fda5815009d68ab90fa6c9cb8ba3580701 (patch) | |
| tree | c43f3da88cb98c435b7590e0831dff986feb6d15 /library/std | |
| parent | d5fa533ab0bfdbb02a1d37ae7787472b20291f11 (diff) | |
| parent | 95ccdb11dab922fa8d6b1b7a24acd82b0b30f071 (diff) | |
| download | rust-b1e0d5fda5815009d68ab90fa6c9cb8ba3580701.tar.gz rust-b1e0d5fda5815009d68ab90fa6c9cb8ba3580701.zip | |
Rollup merge of #85288 - Geal:clarify-std-io-read, r=dtolnay
add an example to explain std::io::Read::read returning 0 in some cases I have always found the explanation about `Read::read` returning 0 to indicate EOF but not indefinitely, so here's more info using Linux as example. I can also add example code if necessary
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/io/mod.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index a8f3412c611..b838a655346 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -526,7 +526,12 @@ pub trait Read { /// /// 1. This reader has reached its "end of file" and will likely no longer /// be able to produce bytes. Note that this does not mean that the - /// reader will *always* no longer be able to produce bytes. + /// reader will *always* no longer be able to produce bytes. As an example, + /// on Linux, this method will call the `recv` syscall for a [`TcpStream`], + /// where returning zero indicates the connection was shut down correctly. While + /// for [`File`], it is possible to reach the end of file and get zero as result, + /// but if more data is appended to the file, future calls to `read` will return + /// more data. /// 2. The buffer specified was 0 bytes in length. /// /// It is not an error if the returned value `n` is smaller than the buffer size, @@ -568,6 +573,7 @@ pub trait Read { /// /// [`Ok(n)`]: Ok /// [`File`]: crate::fs::File + /// [`TcpStream`]: crate::net::TcpStream /// /// ```no_run /// use std::io; |
