Skip to content

Commit

Permalink
Merge pull request #43 from Byron/master
Browse files Browse the repository at this point in the history
Support BlockOn for implementors of AsyncBufRead
  • Loading branch information
taiki-e authored May 18, 2021
2 parents 5707c10 fe1c64f commit 0577901
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 394,16 @@ impl<T: AsyncRead Unpin> std::io::Read for BlockOn<T> {
}
}

impl<T: AsyncBufRead Unpin> std::io::BufRead for BlockOn<T> {
fn fill_buf(&mut self) -> Result<&[u8]> {
future::block_on(self.0.fill_buf())
}

fn consume(&mut self, amt: usize) {
Pin::new(&mut self.0).consume(amt)
}
}

impl<T: AsyncWrite Unpin> std::io::Write for BlockOn<T> {
fn write(&mut self, buf: &[u8]) -> Result<usize> {
future::block_on(self.0.write(buf))
Expand Down

0 comments on commit 0577901

Please sign in to comment.