Skip to content

Commit c6fecbd

Browse files
Merge #171
171: Add BufRead::consume r=stjepang a=yoshuawuyts Ref #131. This implements `BufReader::consume`. Thanks! Note on `fill_buf`: I couldn't get the `async fn fill_buf()` to work, but tracked progress for it here: https://gist.github.com/yoshuawuyts/09bbdc7823225ca96b5e35cd1da5d581. Got some lifetimes isssues. If anyone wants to give this a shot, please do! Co-authored-by: Yoshua Wuyts <[email protected]>
2 parents 5f7a443 + 10fedfe commit c6fecbd

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/io/buf_read/mod.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ cfg_if! {
4343
/// [`futures::io::AsyncBufRead`]:
4444
/// https://docs.rs/futures-preview/0.3.0-alpha.17/futures/io/trait.AsyncBufRead.html
4545
pub trait BufRead {
46+
/// Tells this buffer that `amt` bytes have been consumed from the buffer, so they should no
47+
/// longer be returned in calls to `read`.
48+
fn consume(&mut self, amt: usize)
49+
where
50+
Self: Unpin;
51+
4652
/// Returns the contents of the internal buffer, filling it with more data from the inner
4753
/// reader if it is empty.
4854
///
@@ -217,7 +223,11 @@ pub trait BufRead {
217223
}
218224
}
219225

220-
impl<T: AsyncBufRead + Unpin + ?Sized> BufRead for T {}
226+
impl<T: AsyncBufRead + Unpin + ?Sized> BufRead for T {
227+
fn consume(&mut self, amt: usize) {
228+
AsyncBufRead::consume(Pin::new(self), amt)
229+
}
230+
}
221231

222232
pub fn read_until_internal<R: AsyncBufRead + ?Sized>(
223233
mut reader: Pin<&mut R>,

0 commit comments

Comments
 (0)