Skip to content

Commit 373f93a

Browse files
committed
Implement BufRead for Chain
1 parent deee0f7 commit 373f93a

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/libstd/io/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,27 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
14421442
}
14431443
}
14441444

1445+
#[stable(feature = "chain_bufread", since = "1.9.0")]
1446+
impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
1447+
fn fill_buf(&mut self) -> Result<&[u8]> {
1448+
if !self.done_first {
1449+
match try!(self.first.fill_buf()) {
1450+
buf if buf.len() == 0 => { self.done_first = true; }
1451+
buf => return Ok(buf),
1452+
}
1453+
}
1454+
self.second.fill_buf()
1455+
}
1456+
1457+
fn consume(&mut self, amt: usize) {
1458+
if !self.done_first {
1459+
self.first.consume(amt)
1460+
} else {
1461+
self.second.consume(amt)
1462+
}
1463+
}
1464+
}
1465+
14451466
/// Reader adaptor which limits the bytes read from an underlying reader.
14461467
///
14471468
/// This struct is generally created by calling [`take()`][take] on a reader.

0 commit comments

Comments
 (0)