Struct BufReader
pub struct BufReader<R> { /* private fields */ }
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) -> &RGets a reference to the underlying reader.
It is inadvisable to directly read from the underlying reader.
fn get_mut(&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) -> RConsumes this
BufReader, returning the underlying reader.Note that any leftover data in the internal buffer is lost.
fn buffer(&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.
Trait Implementations
impl<'__pin, R> Unpin for BufReader<R>
where
PinnedFieldsOf<__Origin<'__pin, R>>: Unpin,
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) -> 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: Debug> Debug for BufReader<R>
fn fmt(&self, f: &mut Formatter<'_>) -> Result
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> UnsafeUnpin for BufReader<R>
where
R: UnsafeUnpin,
impl<R> UnwindSafe for BufReader<R>
where
R: UnwindSafe,
Blanket Implementations
impl<R> AsyncBufReadExt for BufReader<R>
where
R: AsyncBufRead + ?Sized,
impl<R> AsyncReadExt for BufReader<R>
where
R: AsyncRead + ?Sized,
impl<S> AsyncSeekExt for BufReader<R>
where
S: AsyncSeek + ?Sized,
impl<T> Any for BufReader<R>
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for BufReader<R>
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for BufReader<R>
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> From<T> for BufReader<R>
fn from(t: T) -> TReturns the argument unchanged.
impl<T, U> Into<U> for BufReader<R>
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for BufReader<R>
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for BufReader<R>
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>