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<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 Vec<u8>
.
Dropping BufWriter<W>
also discards any bytes left in the buffer, so it is
critical to call flush
before BufWriter<W>
is dropped. Calling
flush
ensures that the buffer is empty and thus no data is lost.
Implementations§
Trait Implementations§
source§impl<W: AsyncWrite> AsyncWrite for BufWriter<W>
impl<W: AsyncWrite> AsyncWrite for BufWriter<W>
source§async fn write_vectored<T: IoVectoredBuf>(
&mut self,
buf: T,
) -> BufResult<usize, T>
async fn write_vectored<T: IoVectoredBuf>( &mut self, buf: T, ) -> BufResult<usize, T>
write
, except that it write bytes from a buffer implements
IoVectoredBuf
into the source. Read moreAuto Trait Implementations§
impl<W> Freeze for BufWriter<W>where
W: Freeze,
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> Unpin for BufWriter<W>where
W: Unpin,
impl<W> UnwindSafe for BufWriter<W>where
W: UnwindSafe,
Blanket Implementations§
source§impl<A> AsyncWriteExt for Awhere
A: AsyncWrite + ?Sized,
impl<A> AsyncWriteExt for Awhere
A: AsyncWrite + ?Sized,
source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
AsyncWrite
. Read moresource§async fn write_all<T: IoBuf>(&mut self, buf: T) -> BufResult<(), T>
async fn write_all<T: IoBuf>(&mut self, buf: T) -> BufResult<(), T>
source§async fn write_vectored_all<T: IoVectoredBuf>(
&mut self,
buf: T,
) -> BufResult<(), T>
async fn write_vectored_all<T: IoVectoredBuf>( &mut self, buf: T, ) -> BufResult<(), T>
AsyncWrite::write_vectored
, except that it tries to write the entire
contents of the buffer into this writer.source§async fn write_u8(&mut self, num: u8) -> Result<()>
async fn write_u8(&mut self, num: u8) -> Result<()>
u8
into the underlying writer.source§async fn write_u8_le(&mut self, num: u8) -> Result<()>
async fn write_u8_le(&mut self, num: u8) -> Result<()>
u8
into the underlying writer.source§async fn write_u16(&mut self, num: u16) -> Result<()>
async fn write_u16(&mut self, num: u16) -> Result<()>
u16
into the underlying writer.source§async fn write_u16_le(&mut self, num: u16) -> Result<()>
async fn write_u16_le(&mut self, num: u16) -> Result<()>
u16
into the underlying writer.source§async fn write_u32(&mut self, num: u32) -> Result<()>
async fn write_u32(&mut self, num: u32) -> Result<()>
u32
into the underlying writer.source§async fn write_u32_le(&mut self, num: u32) -> Result<()>
async fn write_u32_le(&mut self, num: u32) -> Result<()>
u32
into the underlying writer.source§async fn write_u64(&mut self, num: u64) -> Result<()>
async fn write_u64(&mut self, num: u64) -> Result<()>
u64
into the underlying writer.source§async fn write_u64_le(&mut self, num: u64) -> Result<()>
async fn write_u64_le(&mut self, num: u64) -> Result<()>
u64
into the underlying writer.source§async fn write_u128(&mut self, num: u128) -> Result<()>
async fn write_u128(&mut self, num: u128) -> Result<()>
u128
into the underlying writer.source§async fn write_u128_le(&mut self, num: u128) -> Result<()>
async fn write_u128_le(&mut self, num: u128) -> Result<()>
u128
into the underlying writer.source§async fn write_i8(&mut self, num: i8) -> Result<()>
async fn write_i8(&mut self, num: i8) -> Result<()>
i8
into the underlying writer.source§async fn write_i8_le(&mut self, num: i8) -> Result<()>
async fn write_i8_le(&mut self, num: i8) -> Result<()>
i8
into the underlying writer.source§async fn write_i16(&mut self, num: i16) -> Result<()>
async fn write_i16(&mut self, num: i16) -> Result<()>
i16
into the underlying writer.source§async fn write_i16_le(&mut self, num: i16) -> Result<()>
async fn write_i16_le(&mut self, num: i16) -> Result<()>
i16
into the underlying writer.source§async fn write_i32(&mut self, num: i32) -> Result<()>
async fn write_i32(&mut self, num: i32) -> Result<()>
i32
into the underlying writer.source§async fn write_i32_le(&mut self, num: i32) -> Result<()>
async fn write_i32_le(&mut self, num: i32) -> Result<()>
i32
into the underlying writer.source§async fn write_i64(&mut self, num: i64) -> Result<()>
async fn write_i64(&mut self, num: i64) -> Result<()>
i64
into the underlying writer.source§async fn write_i64_le(&mut self, num: i64) -> Result<()>
async fn write_i64_le(&mut self, num: i64) -> Result<()>
i64
into the underlying writer.source§async fn write_i128(&mut self, num: i128) -> Result<()>
async fn write_i128(&mut self, num: i128) -> Result<()>
i128
into the underlying writer.source§async fn write_i128_le(&mut self, num: i128) -> Result<()>
async fn write_i128_le(&mut self, num: i128) -> Result<()>
i128
into the underlying writer.source§async fn write_f32(&mut self, num: f32) -> Result<()>
async fn write_f32(&mut self, num: f32) -> Result<()>
f32
into the underlying writer.source§async fn write_f32_le(&mut self, num: f32) -> Result<()>
async fn write_f32_le(&mut self, num: f32) -> Result<()>
f32
into the underlying writer.