diff options
| author | Xavientois <joshua.rampersad@hotmail.com> | 2021-01-15 17:37:29 -0500 |
|---|---|---|
| committer | Xavientois <joshua.rampersad@hotmail.com> | 2021-01-31 08:31:34 -0500 |
| commit | fa76db3104c11416f125be7fcc27d2435dcb84c5 (patch) | |
| tree | 6ddcc3a4050bf634b4c637f8c2e13b2f81eee4a7 /library/std/src/io | |
| parent | c3e47d974ab1c1c4d4b00989631586e60d78b554 (diff) | |
| download | rust-fa76db3104c11416f125be7fcc27d2435dcb84c5.tar.gz rust-fa76db3104c11416f125be7fcc27d2435dcb84c5.zip | |
Use helper trait to follow min_specialization rules
Diffstat (limited to 'library/std/src/io')
| -rw-r--r-- | library/std/src/io/mod.rs | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index e02ee58cdbc..c98f8e383ed 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -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() } } |
