Struct BufReader
struct BufReader<R> { ... }
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
impl<R: AsyncRead> BufReader<R>
fn new(inner: R) -> SelfCreates a new
BufReaderwith a default buffer capacity. The default is currently 8 KB, but may change in the future.fn with_capacity(capacity: usize, inner: R) -> SelfCreates a new
BufReaderwith the specified buffer capacity.fn get_ref(self: &Self) -> &RGets a reference to the underlying reader.
It is inadvisable to directly read from the underlying reader.
fn get_mut(self: &mut Self) -> &mut RGets a mutable reference to the underlying reader.
It is inadvisable to directly read from the underlying reader.
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.
fn into_inner(self: Self) -> RConsumes this
BufReader, returning the underlying reader.Note that any leftover data in the internal buffer is lost.
fn buffer(self: &Self) -> &[u8]Returns a reference to the internally buffered data.
Unlike
fill_buf, this will not attempt to fill the buffer if it is empty.
impl<'__pin, R> Unpin for BufReader<R>
impl<R> AsyncBufReadExt for BufReader<R>
impl<R> AsyncReadExt for BufReader<R>
impl<R> Freeze for BufReader<R>
impl<R> RefUnwindSafe for BufReader<R>
impl<R> Send for BufReader<R>
impl<R> Sync for BufReader<R>
impl<R> UnsafeUnpin for BufReader<R>
impl<R> UnwindSafe for BufReader<R>
impl<R: AsyncRead + AsyncSeek> AsyncSeek for BufReader<R>
fn start_seek(self: Pin<&mut Self>, pos: SeekFrom) -> Result<()>fn poll_complete(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<u64>>
impl<R: AsyncRead + AsyncWrite> AsyncWrite for BufReader<R>
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<R: AsyncRead> AsyncBufRead for BufReader<R>
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>>fn consume(self: Pin<&mut Self>, amt: usize)
impl<R: AsyncRead> AsyncRead for BufReader<R>
fn poll_read(self: Pin<&mut Self>, cx: &mut Context<'_>, buf: &mut ReadBuf<'_>) -> Poll<Result<()>>
impl<R: fmt::Debug> Debug for BufReader<R>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<S> AsyncSeekExt for BufReader<R>
impl<T> Any for BufReader<R>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for BufReader<R>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for BufReader<R>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> From for BufReader<R>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into for BufReader<R>
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 BufReader<R>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for BufReader<R>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>