Skip to content

Commit 32aa327

Browse files
authored
Rollup merge of #65554 - gliderkite:bufreader-doc-enhance, r=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
2 parents d257440 + 5b5196a commit 32aa327

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/libstd/io/buffered.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::memchr;
2424
///
2525
/// When the `BufReader<R>` is dropped, the contents of its buffer will be
2626
/// discarded. Creating multiple instances of a `BufReader<R>` on the same
27-
/// stream can cause data loss.
27+
/// stream can cause data loss. Reading from the underlying reader after
28+
/// unwrapping the `BufReader<R>` with `BufReader::into_inner` can also cause
29+
/// data loss.
2830
///
2931
/// [`Read`]: ../../std/io/trait.Read.html
3032
/// [`TcpStream::read`]: ../../std/net/struct.TcpStream.html#method.read
@@ -179,7 +181,8 @@ impl<R> BufReader<R> {
179181

180182
/// Unwraps this `BufReader<R>`, returning the underlying reader.
181183
///
182-
/// Note that any leftover data in the internal buffer is lost.
184+
/// Note that any leftover data in the internal buffer is lost. Therefore,
185+
/// a following read from the underlying reader may lead to data loss.
183186
///
184187
/// # Examples
185188
///

0 commit comments

Comments
 (0)