Skip to content

Commit c8e4748

Browse files
committed
Update BufWriter example to include call to flush()
1 parent b314654 commit c8e4748

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libstd/io/buffered.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,10 @@ impl<R: Seek> Seek for BufReader<R> {
364364
/// times. It also provides no advantage when writing to a destination that is
365365
/// in memory, like a `Vec<u8>`.
366366
///
367-
/// When the `BufWriter` is dropped, the contents of its buffer will be written
368-
/// out. However, any errors that happen in the process of flushing the buffer
369-
/// when the writer is dropped will be ignored. Code that wishes to handle such
370-
/// errors must manually call [`flush`] before the writer is dropped.
367+
/// It is critical to call [`flush`] before `BufWriter` is dropped. Though
368+
/// dropping will attempt to flush the the contents of the buffer, any errors
369+
/// that happen in the process will be ignored. Calling ['flush'] ensures that
370+
/// the buffer is empty and all errors have been observed.
371371
///
372372
/// # Examples
373373
///
@@ -398,11 +398,12 @@ impl<R: Seek> Seek for BufReader<R> {
398398
/// for i in 0..10 {
399399
/// stream.write(&[i+1]).unwrap();
400400
/// }
401+
/// stream.flush().unwrap();
401402
/// ```
402403
///
403404
/// By wrapping the stream with a `BufWriter`, these ten writes are all grouped
404-
/// together by the buffer, and will all be written out in one system call when
405-
/// the `stream` is dropped.
405+
/// together by the buffer and will all be written out in one system call when
406+
/// the `stream` is flushed.
406407
///
407408
/// [`Write`]: ../../std/io/trait.Write.html
408409
/// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write

0 commit comments

Comments
 (0)