diff --git a/src/libstd/rt/io/extensions.rs b/src/libstd/rt/io/extensions.rs index 0b93a2ad2ca..15ac6544dee 100644 --- a/src/libstd/rt/io/extensions.rs +++ b/src/libstd/rt/io/extensions.rs @@ -71,7 +71,7 @@ pub trait ReaderUtil { /// Raises the same conditions as the `read` method, for /// each call to its `.next()` method. /// Ends the iteration if the condition is handled. - fn bytes(self) -> Bytes; + fn bytes(self) -> ByteIterator; } @@ -349,30 +349,36 @@ impl ReaderUtil for T { return buf; } - fn bytes(self) -> Bytes { - Bytes{reader: self} + fn bytes(self) -> ByteIterator { + ByteIterator{reader: self} } } /// An iterator that reads a single byte on each iteration, -/// until EOF. +/// until `.read_byte()` returns `None`. +/// +/// # Notes about the Iteration Protocol +/// +/// The `ByteIterator` may yield `None` and thus terminate +/// an iteration, but continue to yield elements if iteration +/// is attempted again. /// /// # Failure /// /// Raises the same conditions as the `read` method, for /// each call to its `.next()` method. -/// Ends the iteration if the condition is handled. -pub struct Bytes { +/// Yields `None` if the condition is handled. +pub struct ByteIterator { priv reader: T, } -impl Decorator for Bytes { +impl Decorator for ByteIterator { fn inner(self) -> R { self.reader } fn inner_ref<'a>(&'a self) -> &'a R { &self.reader } fn inner_mut_ref<'a>(&'a mut self) -> &'a mut R { &mut self.reader } } -impl<'self, R: Reader> Iterator for Bytes { +impl<'self, R: Reader> Iterator for ByteIterator { #[inline] fn next(&mut self) -> Option { self.reader.read_byte()