diff options
| author | Mark Simulacrum <mark.simulacrum@gmail.com> | 2017-07-12 06:58:48 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-12 06:58:48 -0600 |
| commit | cc20ab1f2509de4ef0a9953e514d62fa23b6c572 (patch) | |
| tree | ba585ca57d0bd959a72679ff74f26c72181130ed /src/libstd/io | |
| parent | 6aeb0f0b2ed6d9577f741d27e9007b7f787557fa (diff) | |
| parent | c6b280e0396780179a20776b55e3fa4cf4b1a513 (diff) | |
| download | rust-cc20ab1f2509de4ef0a9953e514d62fa23b6c572.tar.gz rust-cc20ab1f2509de4ef0a9953e514d62fa23b6c572.zip | |
Rollup merge of #43136 - jgallag88:bufWriterDocs, r=steveklabnik
Add warning to BufWriter documentation When using `BufWriter`, it is very easy to unintentionally ignore errors, because errors which occur when flushing buffered data when the `BufWriter` is dropped are ignored. This has been noted in a couple places: #32677, #37045. There has been some discussion about how to fix this problem in #32677, but no solution seems likely to land in the near future. For now, anyone who wishes to have robust error handling must remember to manually call `flush()` on a `BufWriter` before it is dropped. Until a permanent fix is in place, it seems worthwhile to add a warning to that effect to the documentation.
Diffstat (limited to 'src/libstd/io')
| -rw-r--r-- | src/libstd/io/buffered.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 296ee78aadb..1b832453523 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -276,7 +276,10 @@ impl<R: Seek> Seek for BufReader<R> { /// `BufWriter` keeps an in-memory buffer of data and writes it to an underlying /// writer in large, infrequent batches. /// -/// The buffer will be written out when the writer is dropped. +/// 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. /// /// # Examples /// @@ -316,6 +319,7 @@ impl<R: Seek> Seek for BufReader<R> { /// [`Write`]: ../../std/io/trait.Write.html /// [`Tcpstream::write`]: ../../std/net/struct.TcpStream.html#method.write /// [`TcpStream`]: ../../std/net/struct.TcpStream.html +/// [`flush`]: #method.flush #[stable(feature = "rust1", since = "1.0.0")] pub struct BufWriter<W: Write> { inner: Option<W>, |
