Implement size_hint for BufReader
This commit is contained in:
parent
0e63af5da3
commit
f45bdcce69
1 changed files with 21 additions and 2 deletions
|
@ -2216,7 +2216,11 @@ impl<T: Read, U: Read> Read for Chain<T, U> {
|
|||
|
||||
unsafe fn initializer(&self) -> Initializer {
|
||||
let initializer = self.first.initializer();
|
||||
if initializer.should_initialize() { initializer } else { self.second.initializer() }
|
||||
if initializer.should_initialize() {
|
||||
initializer
|
||||
} else {
|
||||
self.second.initializer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2235,7 +2239,11 @@ impl<T: BufRead, U: BufRead> BufRead for Chain<T, U> {
|
|||
}
|
||||
|
||||
fn consume(&mut self, amt: usize) {
|
||||
if !self.done_first { self.first.consume(amt) } else { self.second.consume(amt) }
|
||||
if !self.done_first {
|
||||
self.first.consume(amt)
|
||||
} else {
|
||||
self.second.consume(amt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2465,6 +2473,17 @@ impl<R: Read> Iterator for Bytes<R> {
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
default fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(0, None)
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "bufreader_size_hint", since = "1.51.0")]
|
||||
impl<T> Iterator for Bytes<BufReader<T>> {
|
||||
fn size_hint(&self) -> (usize, Option<usize>) {
|
||||
(self.inner.buffer().len(), None)
|
||||
}
|
||||
}
|
||||
|
||||
/// An iterator over the contents of an instance of `BufRead` split on a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue