We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 03753ba commit b46e3eeCopy full SHA for b46e3ee
src/libstd/io/mod.rs
@@ -681,6 +681,21 @@ impl<T: Read> Read for Take<T> {
681
}
682
683
684
+impl<T: BufRead> BufRead for Take<T> {
685
+ fn fill_buf(&mut self) -> Result<&[u8]> {
686
+ let buf = try!(self.inner.fill_buf());
687
+ let cap = cmp::min(buf.len() as u64, self.limit) as usize;
688
+ Ok(&buf[..cap])
689
+ }
690
+
691
+ fn consume(&mut self, amt: usize) {
692
+ // Don't let callers reset the limit by passing an overlarge value
693
+ let amt = cmp::min(amt as u64, self.limit) as usize;
694
+ self.limit -= amt as u64;
695
+ self.inner.consume(amt);
696
697
+}
698
699
/// An adaptor which will emit all read data to a specified writer as well.
700
///
701
/// For more information see `ReadExt::tee`
0 commit comments