implement feedback for bufreader methods

Signed-off-by: Yoshua Wuyts <yoshuawuyts@gmail.com>
This commit is contained in:
Yoshua Wuyts 2019-09-13 02:20:58 +02:00
parent ab0a4cb966
commit 10fedfe97f
No known key found for this signature in database
GPG key ID: 24EA8164F96777ED

View file

@ -43,6 +43,12 @@ cfg_if! {
/// [`futures::io::AsyncBufRead`]: /// [`futures::io::AsyncBufRead`]:
/// https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/trait.AsyncBufRead.html /// https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/trait.AsyncBufRead.html
pub trait BufRead { pub trait BufRead {
/// Tells this buffer that `amt` bytes have been consumed from the buffer, so they should no
/// longer be returned in calls to `read`.
fn consume(&mut self, amt: usize)
where
Self: Unpin;
/// Returns the contents of the internal buffer, filling it with more data from the inner /// Returns the contents of the internal buffer, filling it with more data from the inner
/// reader if it is empty. /// reader if it is empty.
/// ///
@ -63,15 +69,6 @@ pub trait BufRead {
FillBufFuture::new(self) FillBufFuture::new(self)
} }
/// Tells this buffer that `amt` bytes have been consumed from the buffer, so they should no
/// longer be returned in calls to `read`.
fn consume(&mut self, amt: usize)
where
Self: AsyncBufRead + Unpin,
{
AsyncBufRead::consume(Pin::new(self), amt)
}
/// Reads all bytes into `buf` until the delimiter `byte` or EOF is reached. /// Reads all bytes into `buf` until the delimiter `byte` or EOF is reached.
/// ///
/// This function will read bytes from the underlying stream until the delimiter or EOF is /// This function will read bytes from the underlying stream until the delimiter or EOF is
@ -226,7 +223,11 @@ pub trait BufRead {
} }
} }
impl<T: AsyncBufRead + Unpin + ?Sized> BufRead for T {} impl<T: AsyncBufRead + Unpin + ?Sized> BufRead for T {
fn consume(&mut self, amt: usize) {
AsyncBufRead::consume(Pin::new(self), amt)
}
}
pub fn read_until_internal<R: AsyncBufRead + ?Sized>( pub fn read_until_internal<R: AsyncBufRead + ?Sized>(
mut reader: Pin<&mut R>, mut reader: Pin<&mut R>,