Implement size_hint for BufReader
This commit is contained in:
parent
0e63af5da3
commit
f45bdcce69
@ -2216,7 +2216,11 @@ fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize> {
|
||||
|
||||
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 @@ 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) }
|
||||
if !self.done_first {
|
||||
self.first.consume(amt)
|
||||
} else {
|
||||
self.second.consume(amt)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -2465,6 +2473,17 @@ fn next(&mut self) -> Option<Result<u8>> {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
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…
Reference in New Issue
Block a user