diff options
| author | John Erickson <john.t.erickson@gmail.com> | 2019-08-09 06:49:10 -0700 |
|---|---|---|
| committer | John Erickson <john.t.erickson@gmail.com> | 2019-08-31 07:38:02 -0700 |
| commit | c8e474871ab5c13b0bdd92caecfb0bbc99f96541 (patch) | |
| tree | fefafbef59c8ce9e767fc6458c51905b8d6d6ef3 /src/libstd/io | |
| parent | b3146549abf25818fecfc7555f35358a948e27ad (diff) | |
| download | rust-c8e474871ab5c13b0bdd92caecfb0bbc99f96541.tar.gz rust-c8e474871ab5c13b0bdd92caecfb0bbc99f96541.zip | |
Update BufWriter example to include call to flush()
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/buffered.rs | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index aaf628e6c26..70d80a2ea90 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -364,10 +364,10 @@ impl<R: Seek> Seek for BufReader<R> { /// times. It also provides no advantage when writing to a destination that is /// in memory, like a `Vec<u8>`. /// -/// When the `BufWriter` is dropped, the contents of its buffer will be written -/// out. However, any errors that happen in the process of flushing the buffer -/// when the writer is dropped will be ignored. Code that wishes to handle such -/// errors must manually call [`flush`] before the writer is dropped. +/// It is critical to call [`flush`] before `BufWriter` is dropped. Though +/// dropping will attempt to flush the the contents of the buffer, any errors +/// that happen in the process will be ignored. Calling ['flush'] ensures that +/// the buffer is empty and all errors have been observed. /// /// # Examples /// @@ -398,11 +398,12 @@ impl<R: Seek> Seek for BufReader<R> { /// for i in 0..10 { /// stream.write(&[i+1]).unwrap(); /// } +/// stream.flush().unwrap(); /// ``` /// /// By wrapping the stream with a `BufWriter`, these ten writes are all grouped -/// together by the buffer, and will all be written out in one system call when -/// the `stream` is dropped. +/// together by the buffer and will all be written out in one system call when +/// the `stream` is flushed. /// /// [`Write`]: ../../std/io/trait.Write.html /// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write |
