Skip to content

Commit

Permalink
Rollup merge of rust-lang#65554 - gliderkite:bufreader-doc-enhance, r…
Browse files Browse the repository at this point in the history
…=KodrAus

Enhance the documentation of BufReader for potential data loss

This is (IMO) and enhancement of the `std::io::BufReader` documentation, that aims to highlight how relatively easy is to end up with data loss when improperly using an instance of this class.

This is following the issue I had figuring out why my application was loosing data, because I focused my attention on the word *multiple instances* of `BufReader` in its `struct` documentation, even if I ever only had one instance.

Link to the issue: tokio-rs/tokio#1662
  • Loading branch information
JohnTitor authored Nov 8, 2019
2 parents d257440 + 5b5196a commit 32aa327
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/libstd/io/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ use crate::memchr;
///
/// When the `BufReader<R>` is dropped, the contents of its buffer will be
/// discarded. Creating multiple instances of a `BufReader<R>` on the same
/// stream can cause data loss.
/// stream can cause data loss. Reading from the underlying reader after
/// unwrapping the `BufReader<R>` with `BufReader::into_inner` can also cause
/// data loss.
///
/// [`Read`]: ../../std/io/trait.Read.html
/// [`TcpStream::read`]: ../../std/net/struct.TcpStream.html#method.read
Expand Down Expand Up @@ -179,7 +181,8 @@ impl<R> BufReader<R> {

/// Unwraps this `BufReader<R>`, returning the underlying reader.
///
/// Note that any leftover data in the internal buffer is lost.
/// Note that any leftover data in the internal buffer is lost. Therefore,
/// a following read from the underlying reader may lead to data loss.
///
/// # Examples
///
Expand Down

0 comments on commit 32aa327

Please sign in to comment.