about summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorMark Simulacrum <mark.simulacrum@gmail.com>2017-07-12 06:58:48 -0600
committerGitHub <noreply@github.com>2017-07-12 06:58:48 -0600
commitcc20ab1f2509de4ef0a9953e514d62fa23b6c572 (patch)
treeba585ca57d0bd959a72679ff74f26c72181130ed /src/libstd/io
parent6aeb0f0b2ed6d9577f741d27e9007b7f787557fa (diff)
parentc6b280e0396780179a20776b55e3fa4cf4b1a513 (diff)
downloadrust-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.rs6
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>,