diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index 3f5b7c0b29be6..20cffc09fd2a8 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -253,6 +253,7 @@ mod tests; use crate::cmp; use crate::fmt; +use crate::fs; use crate::memchr; use crate::ops::{Deref, DerefMut}; use crate::ptr; @@ -2462,6 +2463,23 @@ impl Iterator for Bytes { }; } } + + default fn size_hint(&self) -> (usize, Option) { + (0, None) + } +} + +#[unstable] +impl Iterator for Bytes { + fn size_hint(&self) -> (usize, Option) { + match self.inner.metadata() { + Ok(metadata) => { + let file_length = metadata.len() as usize; + (0, Some(file_length)) + } + Err(_) => (0, None), + } + } } /// An iterator over the contents of an instance of `BufRead` split on a