pub struct BufReader<'buf, R> { /* private fields */ }
io
only.Expand description
The BufReader
struct adds buffering to any reader.
It can be excessively inefficient to work directly with a AsyncRead
instance. A BufReader
performs large, infrequent reads on the underlying
AsyncRead
and maintains an in-memory buffer of the results.
BufReader
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
is dropped, the contents of its buffer will be
discarded. Creating multiple instances of a BufReader
on the same
stream can cause data loss.
Implementations§
Source§impl<'buf, R: AsyncRead> BufReader<'buf, R>
impl<'buf, R: AsyncRead> BufReader<'buf, R>
Sourcepub fn new(buf: &'buf mut [u8], inner: R) -> Self
pub fn new(buf: &'buf mut [u8], inner: R) -> Self
Creates a new BufReader
with the specified buffer capacity.
Sourcepub fn get_ref(&self) -> &R
pub fn get_ref(&self) -> &R
Gets a reference to the underlying reader.
It is inadvisable to directly read from the underlying reader.
Sourcepub fn get_mut(&mut self) -> &mut R
pub fn get_mut(&mut self) -> &mut R
Gets a mutable reference to the underlying reader.
It is inadvisable to directly read from the underlying reader.
Sourcepub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut R>
pub fn get_pin_mut(self: Pin<&mut Self>) -> Pin<&mut R>
Gets a pinned mutable reference to the underlying reader.
It is inadvisable to directly read from the underlying reader.
Sourcepub fn into_inner(self) -> R
pub fn into_inner(self) -> R
Consumes this BufReader
, returning the underlying reader.
Note that any leftover data in the internal buffer is lost.