diff --git a/library/std/src/io/mod.rs b/library/std/src/io/mod.rs index c93bf0202523a..3c5fa84b87f5b 100644 --- a/library/std/src/io/mod.rs +++ b/library/std/src/io/mod.rs @@ -1000,7 +1000,7 @@ pub trait Read { where Self: Sized, { - Bytes { inner: self } + Bytes { inner: self, byte: 0 } } /// Creates an adapter which will chain this stream with another. @@ -2772,24 +2772,23 @@ impl SizeHint for Take { #[derive(Debug)] pub struct Bytes { inner: R, + byte: u8, } #[stable(feature = "rust1", since = "1.0.0")] impl Iterator for Bytes { type Item = Result; + #[inline] fn next(&mut self) -> Option> { - let mut byte = 0; - loop { - return match self.inner.read(slice::from_mut(&mut byte)) { - Ok(0) => None, - Ok(..) => Some(Ok(byte)), - Err(ref e) if e.is_interrupted() => continue, - Err(e) => Some(Err(e)), - }; + match self.inner.read_exact(slice::from_mut(&mut self.byte)) { + Ok(()) => Some(Ok(self.byte)), + Err(e) if e.kind() == ErrorKind::UnexpectedEof => None, + Err(e) => Some(Err(e)), } } + #[inline] fn size_hint(&self) -> (usize, Option) { SizeHint::size_hint(&self.inner) }