2
0
Fork 1
mirror of https://github.com/async-rs/async-std.git synced 2025-04-13 20:06:43 +00:00
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 <yoshuawuyts@gmail.com>
This commit is contained in:
bors[bot] 2019-09-16 06:38:44 +00:00 committed by GitHub
commit c6fecbd4ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.
///
@ -217,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>(
mut reader: Pin<&mut R>,