From ab0a4cb966087fff0520ccb13d3c4c88e6b02c58 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Tue, 10 Sep 2019 13:18:07 +0200 Subject: [PATCH 1/2] remove pin bounds from consume Signed-off-by: Yoshua Wuyts --- src/io/buf_read/mod.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/io/buf_read/mod.rs b/src/io/buf_read/mod.rs index 6018439a9..65741fdcd 100644 --- a/src/io/buf_read/mod.rs +++ b/src/io/buf_read/mod.rs @@ -63,6 +63,15 @@ 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 From 10fedfe97fc0c7e6b76790da53c3d5053dde6636 Mon Sep 17 00:00:00 2001 From: Yoshua Wuyts Date: Fri, 13 Sep 2019 02:20:58 +0200 Subject: [PATCH 2/2] 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 65741fdcd..b65d17704 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>,