The Reader can implement BufReader naturally (#232)

There's no reason the user should be forced to wrap it in BufReader in
case the trait is needed, because the Reader has all the bits for
supporting it naturally.
This commit is contained in:
Michal 'vorner' Vaner
2018-11-17 07:51:41 -08:00
committed by Carl Lerche
parent e64a123d00
commit 7c3085aaec
2 changed files with 37 additions and 0 deletions
+9
View File
@@ -86,3 +86,12 @@ impl<B: Buf + Sized> io::Read for Reader<B> {
Ok(len)
}
}
impl<B: Buf + Sized> io::BufRead for Reader<B> {
fn fill_buf(&mut self) -> io::Result<&[u8]> {
Ok(self.buf.bytes())
}
fn consume(&mut self, amt: usize) {
self.buf.advance(amt)
}
}