io::Chain
: specialize some BufRead
methods
This commit is contained in:
parent
cada71e3f4
commit
cba6e102ec
@ -2429,9 +2429,7 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
||||
fn fill_buf(&mut self) -> Result<&[u8]> {
|
||||
if !self.done_first {
|
||||
match self.first.fill_buf()? {
|
||||
buf if buf.is_empty() => {
|
||||
self.done_first = true;
|
||||
}
|
||||
buf if buf.is_empty() => self.done_first = true,
|
||||
buf => return Ok(buf),
|
||||
}
|
||||
}
|
||||
@ -2441,6 +2439,21 @@ fn fill_buf(&mut self) -> Result<&[u8]> {
|
||||
fn consume(&mut self, amt: usize) {
|
||||
if !self.done_first { self.first.consume(amt) } else { self.second.consume(amt) }
|
||||
}
|
||||
|
||||
fn read_until(&mut self, byte: u8, buf: &mut Vec<u8>) -> Result<usize> {
|
||||
let mut read = 0;
|
||||
if !self.done_first {
|
||||
let n = self.first.read_until(byte, buf)?;
|
||||
read += n;
|
||||
|
||||
match buf.last() {
|
||||
Some(b) if *b == byte && n != 0 => return Ok(read),
|
||||
_ => self.done_first = true,
|
||||
}
|
||||
}
|
||||
read += self.second.read_until(byte, buf)?;
|
||||
Ok(read)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, U> SizeHint for Chain<T, U> {
|
||||
|
Loading…
Reference in New Issue
Block a user