Use helper trait to follow min_specialization rules

This commit is contained in:
Xavientois 2021-01-15 17:37:29 -05:00
parent c3e47d974a
commit fa76db3104

View File

@ -2459,7 +2459,7 @@ pub struct Bytes<R> {
}
#[stable(feature = "rust1", since = "1.0.0")]
impl<R: Read> Iterator for Bytes<R> {
impl<R: Read + SizeHint> Iterator for Bytes<R> {
type Item = Result<u8>;
fn next(&mut self) -> Option<Result<u8>> {
@ -2475,14 +2475,34 @@ impl<R: Read> Iterator for Bytes<R> {
}
default fn size_hint(&self) -> (usize, Option<usize>) {
(0, None)
self.inner.size_hint()
}
}
#[stable(feature = "bufreader_size_hint", since = "1.51.0")]
impl<R: Read> Iterator for Bytes<BufReader<R>> {
trait SizeHint {
fn lower_bound(&self) -> usize;
fn upper_bound(&self) -> Option<usize> {
None
}
fn size_hint(&self) -> (usize, Option<usize>) {
(self.inner.buffer().len(), None)
(self.lower_bound(), self.upper_bound())
}
}
#[stable(feature = "bufreader_size_hint", since = "1.51.0")]
impl SizeHint for T {
fn lower_bound(&self) -> usize {
0
}
}
#[stable(feature = "bufreader_size_hint", since = "1.51.0")]
impl<T> SizeHint for BufReader<T> {
fn lower_bound(&self) -> usize {
self.buffer().len()
}
}