Struct BufWriter
struct BufWriter<W> { ... }
Wraps a writer and buffers its output.
It can be excessively inefficient to work directly with something that
implements AsyncWrite. A BufWriter keeps an in-memory buffer of data and
writes it to an underlying writer in large, infrequent batches.
BufWriter 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 Vec<u8>.
When the BufWriter is dropped, the contents of its buffer will be
discarded. Creating multiple instances of a BufWriter on the same
stream can cause data loss. If you need to write out the contents of its
buffer, you must manually call flush before the writer is dropped.
Implementations
impl<W: AsyncWrite> BufWriter<W>
fn new(inner: W) -> SelfCreates a new
BufWriterwith a default buffer capacity. The default is currently 8 KB, but may change in the future.fn with_capacity(cap: usize, inner: W) -> SelfCreates a new
BufWriterwith the specified buffer capacity.fn get_ref(self: &Self) -> &WGets a reference to the underlying writer.
fn get_mut(self: &mut Self) -> &mut WGets a mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut W>Gets a pinned mutable reference to the underlying writer.
It is inadvisable to directly write to the underlying writer.
fn into_inner(self: Self) -> WConsumes this
BufWriter, returning the underlying writer.Note that any leftover data in the internal buffer is lost.
fn buffer(self: &Self) -> &[u8]Returns a reference to the internally buffered data.
impl<'__pin, W> Unpin for BufWriter<W>
impl<R> AsyncBufReadExt for BufWriter<W>
impl<R> AsyncReadExt for BufWriter<W>
impl<S> AsyncSeekExt for BufWriter<W>
impl<T> Any for BufWriter<W>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for BufWriter<W>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for BufWriter<W>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for BufWriter<W>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for BufWriter<W>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for BufWriter<W>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for BufWriter<W>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<W> AsyncWriteExt for BufWriter<W>
impl<W> Freeze for BufWriter<W>
impl<W> RefUnwindSafe for BufWriter<W>
impl<W> Send for BufWriter<W>
impl<W> Sync for BufWriter<W>
impl<W> UnsafeUnpin for BufWriter<W>
impl<W> UnwindSafe for BufWriter<W>
impl<W: AsyncWrite + AsyncBufRead> AsyncBufRead for BufWriter<W>
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>>fn consume(self: Pin<&mut Self>, amt: usize)
impl<W: AsyncWrite + AsyncRead> AsyncRead for BufWriter<W>
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<()>>
impl<W: AsyncWrite + AsyncSeek> AsyncSeek for BufWriter<W>
fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>fn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<u64>>
impl<W: AsyncWrite> AsyncWrite for BufWriter<W>
fn poll_write(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>fn poll_write_vectored(self: Pin<&mut Self>, cx: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize>>fn is_write_vectored(self: &Self) -> boolfn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
impl<W: fmt::Debug> Debug for BufWriter<W>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result