Wraps a writer and buffers its output.
It can be excessively inefficient to work directly with something that
Write. For example, every call to
TcpStream results in a system call. A
BufWriter<W> keeps an in-memory buffer of data and writes it to an underlying
writer in large, infrequent batches.
BufWriter<W> can improve the speed of programs that make small and
repeated write calls to the same file or network socket. It does not
help when writing very large amounts at once, or writing just one or a few
times. It also provides no advantage when writing to a destination that is
in memory, like a
It is critical to call
BufWriter<W> is dropped. Though
dropping will attempt to flush the the contents of the buffer, any errors
that happen in the process of dropping will be ignored. Calling
ensures that the buffer is empty and thus dropping will not even attempt
By wrapping the stream with a
BufWriter<W>, these ten writes are all grouped
together by the buffer and will all be written out in one system call when
stream is flushed.
impl<W: Write> BufWriter<W>[src]
Creates a new
BufWriter<W> with a default buffer capacity. The default is currently 8 KB,
but may change in the future.
pub fn with_capacity(capacity: usize, inner: W) -> BufWriter<W>[src]
Creates a new
BufWriter<W> with the specified buffer capacity.
Gets a reference to the underlying writer.
Gets a mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
Returns a reference to the internally buffered data.
Returns the number of bytes the internal buffer can hold without flushing.
pub fn into_inner(self) -> Result<W, IntoInnerError<BufWriter<W>>>[src]
BufWriter<W>, returning the underlying writer.
The buffer is written out before returning the writer.
Err will be returned if an error occurs while flushing the buffer.
Seek to the offset, in bytes, in the underlying writer.
Seeking always writes out the internal buffer before seeking.
fn stream_len(&mut self) -> Result<u64>[src]
fn stream_position(&mut self) -> Result<u64>[src]
fn write_vectored(&mut self, bufs: &[IoSlice]) -> Result<usize>[src]
fn write_all_vectored(&mut self, bufs: &mut [IoSlice]) -> Result<()>[src]
Auto Trait Implementations
impl<W> RefUnwindSafe for BufWriter<W> where
impl<W> UnwindSafe for BufWriter<W> where
type Error = Infallible
The type returned in the event of a conversion error.