mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-07 17:18:32 +03:00
Update BufWriter example to include call to flush()
This commit is contained in:
@@ -364,10 +364,10 @@ fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
||||
/// times. It also provides no advantage when writing to a destination that is
|
||||
/// in memory, like a `Vec<u8>`.
|
||||
///
|
||||
/// 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.
|
||||
/// It is critical to call [`flush`] before `BufWriter` is dropped. Though
|
||||
/// dropping will attempt to flush the the contents of the buffer, any errors
|
||||
/// that happen in the process will be ignored. Calling ['flush'] ensures that
|
||||
/// the buffer is empty and all errors have been observed.
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
@@ -398,11 +398,12 @@ fn seek(&mut self, pos: SeekFrom) -> io::Result<u64> {
|
||||
/// for i in 0..10 {
|
||||
/// stream.write(&[i+1]).unwrap();
|
||||
/// }
|
||||
/// stream.flush().unwrap();
|
||||
/// ```
|
||||
///
|
||||
/// By wrapping the stream with a `BufWriter`, these ten writes are all grouped
|
||||
/// together by the buffer, and will all be written out in one system call when
|
||||
/// the `stream` is dropped.
|
||||
/// together by the buffer and will all be written out in one system call when
|
||||
/// the `stream` is flushed.
|
||||
///
|
||||
/// [`Write`]: ../../std/io/trait.Write.html
|
||||
/// [`TcpStream::write`]: ../../std/net/struct.TcpStream.html#method.write
|
||||
|
||||
Reference in New Issue
Block a user