Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsyncBufRead implementation for ProgressBarIter #315

Merged
merged 7 commits into from Oct 11, 2021
18 changes: 18 additions & 0 deletions src/iter.rs
Expand Up @@ -200,6 +200,24 @@ impl<W: tokio::io::AsyncSeek + Unpin> tokio::io::AsyncSeek for ProgressBarIter<W
}
}

#[cfg(feature = "tokio")]
x0f5c3 marked this conversation as resolved.
Show resolved Hide resolved
impl<W: tokio::io::AsyncBufRead + Unpin + tokio::io::AsyncRead> tokio::io::AsyncBufRead
for ProgressBarIter<W>
{
fn poll_fill_buf(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<&[u8]>> {
let this = self.get_mut();
let result = Pin::new(&mut this.it).poll_fill_buf(cx);
if let Poll::Ready(Ok(buf)) = &result {
this.progress.inc(buf.len() as u64);
}
result
}

fn consume(mut self: Pin<&mut Self>, amt: usize) {
Pin::new(&mut self.it).consume(amt);
}
}

impl<W: io::Write> io::Write for ProgressBarIter<W> {
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
self.it.write(buf).map(|inc| {
Expand Down