pub struct BufReader<R> { /* private fields */ }
Expand description
Wraps a reader and buffers input from AsyncRead
It can be excessively inefficient to work directly with a AsyncRead
instance. A BufReader<R>
performs large, infrequent reads on the
underlying AsyncRead
and maintains an in-memory buffer of the results.
BufReader<R>
can improve the speed of programs that make small and
repeated read calls to the same file or network socket. It does not
help when reading very large amounts at once, or reading just one or a few
times. It also provides no advantage when reading from a source that is
already in memory, like a Vec<u8>
.
When the BufReader<R>
is dropped, the contents of its buffer will be
discarded. Reading from the underlying reader after unwrapping the
BufReader<R>
with BufReader::into_inner
can cause data loss.
§Caution
Due to the pass-by-ownership nature of completion-based IO, the buffer is
passed to the inner reader when fill_buf
is called. If the future
returned by fill_buf
is dropped before inner read
is completed,
BufReader
will not be able to retrieve the buffer, causing panic on next
fill_buf
call.
Implementations§
Trait Implementations§
source§impl<R: AsyncRead> AsyncBufRead for BufReader<R>
impl<R: AsyncRead> AsyncBufRead for BufReader<R>
source§impl<R: AsyncRead> AsyncRead for BufReader<R>
impl<R: AsyncRead> AsyncRead for BufReader<R>
Auto Trait Implementations§
impl<R> Freeze for BufReader<R>where
R: Freeze,
impl<R> RefUnwindSafe for BufReader<R>where
R: RefUnwindSafe,
impl<R> Send for BufReader<R>where
R: Send,
impl<R> Sync for BufReader<R>where
R: Sync,
impl<R> Unpin for BufReader<R>where
R: Unpin,
impl<R> UnwindSafe for BufReader<R>where
R: UnwindSafe,
Blanket Implementations§
source§impl<A> AsyncReadExt for A
impl<A> AsyncReadExt for A
source§async fn read_exact<T: IoBufMut>(&mut self, buf: T) -> BufResult<(), T>
async fn read_exact<T: IoBufMut>(&mut self, buf: T) -> BufResult<(), T>
source§async fn read_to_end(&mut self, buf: Vec<u8>) -> BufResult<usize, Vec<u8>>
async fn read_to_end(&mut self, buf: Vec<u8>) -> BufResult<usize, Vec<u8>>
EOF
.source§async fn read_vectored_exact<T: IoVectoredBufMut>(
&mut self,
buf: T,
) -> BufResult<(), T>
async fn read_vectored_exact<T: IoVectoredBufMut>( &mut self, buf: T, ) -> BufResult<(), T>
source§fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
fn take(self, limit: u64) -> Take<Self>where
Self: Sized,
limit
bytes from it. Read moresource§async fn read_u8_le(&mut self) -> Result<u8>
async fn read_u8_le(&mut self) -> Result<u8>
u8
from the underlying reader.source§async fn read_u16_le(&mut self) -> Result<u16>
async fn read_u16_le(&mut self) -> Result<u16>
u16
from the underlying reader.source§async fn read_u32_le(&mut self) -> Result<u32>
async fn read_u32_le(&mut self) -> Result<u32>
u32
from the underlying reader.source§async fn read_u64_le(&mut self) -> Result<u64>
async fn read_u64_le(&mut self) -> Result<u64>
u64
from the underlying reader.source§async fn read_u128(&mut self) -> Result<u128>
async fn read_u128(&mut self) -> Result<u128>
u128
from the underlying reader.source§async fn read_u128_le(&mut self) -> Result<u128>
async fn read_u128_le(&mut self) -> Result<u128>
u128
from the underlying reader.source§async fn read_i8_le(&mut self) -> Result<i8>
async fn read_i8_le(&mut self) -> Result<i8>
i8
from the underlying reader.source§async fn read_i16_le(&mut self) -> Result<i16>
async fn read_i16_le(&mut self) -> Result<i16>
i16
from the underlying reader.source§async fn read_i32_le(&mut self) -> Result<i32>
async fn read_i32_le(&mut self) -> Result<i32>
i32
from the underlying reader.source§async fn read_i64_le(&mut self) -> Result<i64>
async fn read_i64_le(&mut self) -> Result<i64>
i64
from the underlying reader.source§async fn read_i128(&mut self) -> Result<i128>
async fn read_i128(&mut self) -> Result<i128>
i128
from the underlying reader.source§async fn read_i128_le(&mut self) -> Result<i128>
async fn read_i128_le(&mut self) -> Result<i128>
i128
from the underlying reader.source§async fn read_f32_le(&mut self) -> Result<f32>
async fn read_f32_le(&mut self) -> Result<f32>
f32
from the underlying reader.source§async fn read_f64_le(&mut self) -> Result<f64>
async fn read_f64_le(&mut self) -> Result<f64>
f64
from the underlying reader.