diff options
| author | blake2-ppc <blake2-ppc> | 2013-09-03 20:00:32 +0200 |
|---|---|---|
| committer | blake2-ppc <blake2-ppc> | 2013-09-03 20:06:45 +0200 |
| commit | 913d1b48ad4e2dd909009aab93837cd596a235b2 (patch) | |
| tree | 1d8dc2f84524e6414455ec726a42f5a9da3f2ee3 /src/libstd/rt | |
| parent | 61026ae621ffbc6d7538cfb0add49b8fc5638e86 (diff) | |
| download | rust-913d1b48ad4e2dd909009aab93837cd596a235b2.tar.gz rust-913d1b48ad4e2dd909009aab93837cd596a235b2.zip | |
rt::io: Rename Bytes to ByteIterator and add note about iteration
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/io/extensions.rs | 22 |
1 files changed, 14 insertions, 8 deletions
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<Self>; + fn bytes(self) -> ByteIterator<Self>; } @@ -349,30 +349,36 @@ impl<T: Reader> ReaderUtil for T { return buf; } - fn bytes(self) -> Bytes<T> { - Bytes{reader: self} + fn bytes(self) -> ByteIterator<T> { + 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<T> { +/// Yields `None` if the condition is handled. +pub struct ByteIterator<T> { priv reader: T, } -impl<R> Decorator<R> for Bytes<R> { +impl<R> Decorator<R> for ByteIterator<R> { 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<u8> for Bytes<R> { +impl<'self, R: Reader> Iterator<u8> for ByteIterator<R> { #[inline] fn next(&mut self) -> Option<u8> { self.reader.read_byte() |
