pub struct BufWriter<W> { /* private fields */ }
Expand description
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§
source§impl<W> BufWriter<W>where
W: AsyncWrite,
impl<W> BufWriter<W>where
W: AsyncWrite,
sourcepub fn new(inner: W) -> BufWriter<W>
pub fn new(inner: W) -> BufWriter<W>
Creates a new BufWriter
with a default buffer capacity. The default is currently 8 KB,
but may change in the future.
sourcepub fn with_capacity(cap: usize, inner: W) -> BufWriter<W>
pub fn with_capacity(cap: usize, inner: W) -> BufWriter<W>
Creates a new BufWriter
with the specified buffer capacity.
sourcepub fn get_ref(&self) -> &W
pub fn get_ref(&self) -> &W
Acquires a reference to the underlying sink or stream that this combinator is pulling from.
sourcepub fn get_mut(&mut self) -> &mut W
pub fn get_mut(&mut self) -> &mut W
Acquires a mutable reference to the underlying sink or stream that this combinator is pulling from.
Note that care must be taken to avoid tampering with the state of the sink or stream which may otherwise confuse this combinator.
sourcepub fn get_pin_mut(self: Pin<&mut BufWriter<W>>) -> Pin<&mut W>
pub fn get_pin_mut(self: Pin<&mut BufWriter<W>>) -> Pin<&mut W>
Acquires a pinned mutable reference to the underlying sink or stream that this combinator is pulling from.
Note that care must be taken to avoid tampering with the state of the sink or stream which may otherwise confuse this combinator.
sourcepub fn into_inner(self) -> W
pub fn into_inner(self) -> W
Consumes this combinator, returning the underlying sink or stream.
Note that this may discard intermediate state of this combinator, so care should be taken to avoid losing resources when this is called.
Trait Implementations§
source§impl<W> AsyncBufRead for BufWriter<W>where
W: AsyncBufRead,
impl<W> AsyncBufRead for BufWriter<W>where
W: AsyncBufRead,
source§impl<W> AsyncRead for BufWriter<W>where
W: AsyncRead,
impl<W> AsyncRead for BufWriter<W>where
W: AsyncRead,
source§impl<W> AsyncWrite for BufWriter<W>where
W: AsyncWrite,
impl<W> AsyncWrite for BufWriter<W>where
W: AsyncWrite,
source§fn poll_write(
self: Pin<&mut BufWriter<W>>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write(
self: Pin<&mut BufWriter<W>>,
cx: &mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
buf
into the object. Read moresource§fn poll_write_vectored(
self: Pin<&mut BufWriter<W>>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut BufWriter<W>>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
bufs
into the object using vectored
IO operations. Read moreimpl<'__pin, W> Unpin for BufWriter<W>where
__Origin<'__pin, W>: Unpin,
Auto Trait Implementations§
impl<W> RefUnwindSafe for BufWriter<W>where
W: RefUnwindSafe,
impl<W> Send for BufWriter<W>where
W: Send,
impl<W> Sync for BufWriter<W>where
W: Sync,
impl<W> UnwindSafe for BufWriter<W>where
W: UnwindSafe,
Blanket Implementations§
source§impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
source§fn fill_buf(&mut self) -> FillBuf<'_, Self> ⓘwhere
Self: Unpin,
fn fill_buf(&mut self) -> FillBuf<'_, Self> ⓘwhere
Self: Unpin,
source§fn consume_unpin(&mut self, amt: usize)where
Self: Unpin,
fn consume_unpin(&mut self, amt: usize)where
Self: Unpin,
source§fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntil<'a, Self> ⓘwhere
Self: Unpin,
fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntil<'a, Self> ⓘwhere
Self: Unpin,
buf
until the delimiter byte
or EOF is reached.
This method is the async equivalent to BufRead::read_until
. Read moresource§fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> ⓘwhere
Self: Unpin,
fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self> ⓘwhere
Self: Unpin,
buf
until a newline (the 0xA byte) or EOF is reached,
This method is the async equivalent to BufRead::read_line
. Read moresource§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
source§fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
fn chain<R>(self, next: R) -> Chain<Self, R>where
Self: Sized,
R: AsyncRead,
source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> ⓘwhere
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self> ⓘwhere
Self: Unpin,
buf
in asynchronous
manner, returning a future type. Read moresource§fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> ⓘwhere
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self> ⓘwhere
Self: Unpin,
AsyncRead
into bufs
using vectored
IO operations. Read moresource§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> ⓘwhere
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self> ⓘwhere
Self: Unpin,
buf
,
returning an error if end of file (EOF) is hit sooner. Read moresource§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEnd<'a, Self> ⓘwhere
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEnd<'a, Self> ⓘwhere
Self: Unpin,
AsyncRead
. Read moresource§fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToString<'a, Self> ⓘwhere
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToString<'a, Self> ⓘwhere
Self: Unpin,
AsyncRead
. Read moresource§impl<S> AsyncSeekExt for Swhere
S: AsyncSeek + ?Sized,
impl<S> AsyncSeekExt for Swhere
S: AsyncSeek + ?Sized,
source§impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for Wwhere
W: AsyncWrite + ?Sized,
source§fn flush(&mut self) -> Flush<'_, Self> ⓘwhere
Self: Unpin,
fn flush(&mut self) -> Flush<'_, Self> ⓘwhere
Self: Unpin,
AsyncWrite
. Read moresource§fn close(&mut self) -> Close<'_, Self> ⓘwhere
Self: Unpin,
fn close(&mut self) -> Close<'_, Self> ⓘwhere
Self: Unpin,
AsyncWrite
.source§fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘwhere
Self: Unpin,
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Write<'a, Self> ⓘwhere
Self: Unpin,
buf
into the object. Read moresource§fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self> ⓘwhere
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self> ⓘwhere
Self: Unpin,
bufs
into the object using vectored
IO operations. Read more