diff options
| author | Tobias Müller <troplin@bluewin.ch> | 2016-03-28 01:28:03 +0200 |
|---|---|---|
| committer | Tobias Müller <troplin@bluewin.ch> | 2016-03-28 01:28:03 +0200 |
| commit | 373f93a629313dccd1858e403e99fb25709947a4 (patch) | |
| tree | af3ca261dbfcd81f5b04cf5aaf7d7aef5e887b9f /src/libstd | |
| parent | deee0f73da885a71ebf9c8d29213c663dba467b9 (diff) | |
| download | rust-373f93a629313dccd1858e403e99fb25709947a4.tar.gz rust-373f93a629313dccd1858e403e99fb25709947a4.zip | |
Implement BufRead for Chain
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/io/mod.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index 28492b30e0f..ce14e5de90a 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -1442,6 +1442,27 @@ impl<T: Read, U: Read> Read for Chain<T, U> { } } +#[stable(feature = "chain_bufread", since = "1.9.0")] +impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> { + fn fill_buf(&mut self) -> Result<&[u8]> { + if !self.done_first { + match try!(self.first.fill_buf()) { + buf if buf.len() == 0 => { self.done_first = true; } + buf => return Ok(buf), + } + } + self.second.fill_buf() + } + + fn consume(&mut self, amt: usize) { + if !self.done_first { + self.first.consume(amt) + } else { + self.second.consume(amt) + } + } +} + /// Reader adaptor which limits the bytes read from an underlying reader. /// /// This struct is generally created by calling [`take()`][take] on a reader. |
