std: Implement the Buffer trait for some wrappers

This will allow methods like read_line() on RefReader, LimitReader, etc.
This commit is contained in:
Alex Crichton
2014-05-05 23:50:07 -07:00
parent ef6daf9935
commit 678b1659f9
2 changed files with 63 additions and 1 deletions

View File

@@ -853,6 +853,11 @@ impl<'a, R: Reader> Reader for RefReader<'a, R> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> { self.inner.read(buf) }
}
impl<'a, R: Buffer> Buffer for RefReader<'a, R> {
fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> { self.inner.fill_buf() }
fn consume(&mut self, amt: uint) { self.inner.consume(amt) }
}
fn extend_sign(val: u64, nbytes: uint) -> i64 {
let shift = (8 - nbytes) * 8;
(val << shift) as i64 >> shift