Trait AsyncBufRead
trait AsyncBufRead: AsyncRead
Reads bytes asynchronously.
This trait is analogous to std::io::BufRead, but integrates with
the asynchronous task system. In particular, the poll_fill_buf method,
unlike BufRead::fill_buf, will automatically queue the current task for wakeup
and return if data is not yet available, rather than blocking the calling
thread.
Utilities for working with AsyncBufRead values are provided by
AsyncBufReadExt.
Required Methods
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<&[u8]>>Attempts to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty.
On success, returns
Poll::Ready(Ok(buf)).If no data is available for reading, the method returns
Poll::Pendingand arranges for the current task (viacx.waker().wake_by_ref()) to receive a notification when the object becomes readable or is closed.This function is a lower-level call. It needs to be paired with the
consumemethod to function properly. When calling this method, none of the contents will be "read" in the sense that later callingpoll_readmay return the same contents. As such,consumemust be called with the number of bytes that are consumed from this buffer to ensure that the bytes are never returned twice.An empty buffer returned indicates that the stream has reached EOF.
fn consume(self: Pin<&mut Self>, amt: usize)Tells this buffer that
amtbytes have been consumed from the buffer, so they should no longer be returned in calls topoll_read.This function is a lower-level call. It needs to be paired with the
poll_fill_bufmethod to function properly. This function does not perform any I/O, it simply informs this object that some amount of its buffer, returned frompoll_fill_buf, has been consumed and should no longer be returned. As such, this function may do odd things ifpoll_fill_bufisn't called before calling it.The
amtmust be<=the number of bytes in the buffer returned bypoll_fill_buf.
Implementors
impl<R: AsyncBufRead> AsyncBufRead for Take<R>impl<T: ?Sized + AsyncBufRead + Unpin> AsyncBufRead for &mut Timpl<R, W> AsyncBufRead for Join<R, W>impl<RW: AsyncRead + AsyncWrite> AsyncBufRead for BufStream<RW>impl<R: AsyncRead> AsyncBufRead for BufReader<R>impl AsyncBufRead for Emptyimpl<T: ?Sized + AsyncBufRead + Unpin> AsyncBufRead for Box<T>impl<T: AsRef<[u8]> + Unpin> AsyncBufRead for Cursor<T>impl<W: AsyncWrite + AsyncBufRead> AsyncBufRead for BufWriter<W>impl<P> AsyncBufRead for Pin<P>impl AsyncBufRead for &[u8]