From 10fedfe97fc0c7e6b76790da53c3d5053dde6636 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 13 Sep 2019 02:20:58 +0200 Subject: [PATCH] implement feedback for bufreader methods Signed-off-by: Yoshua Wuyts --- src/io/buf_read/mod.rs | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index 65741fd..b65d177 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -43,6 +43,12 @@ cfg_if! { /// [`futures::io::AsyncBufRead`]: /// https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/trait.AsyncBufRead.html 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 /// reader if it is empty. /// @@ -63,15 +69,6 @@ pub trait BufRead { 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. /// /// This function will read bytes from the underlying stream until the delimiter or EOF is @@ -226,7 +223,11 @@ pub trait BufRead { } } -impl BufRead for T {} +impl BufRead for T { + fn consume(&mut self, amt: usize) { + AsyncBufRead::consume(Pin::new(self), amt) + } +} pub fn read_until_internal( mut reader: Pin<&mut R>,