Skip to content

Commit 913d1b4

Browse files
author
blake2-ppc
committed
rt::io: Rename Bytes to ByteIterator and add note about iteration
1 parent 61026ae commit 913d1b4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/libstd/rt/io/extensions.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ pub trait ReaderUtil {
7171
/// Raises the same conditions as the `read` method, for
7272
/// each call to its `.next()` method.
7373
/// Ends the iteration if the condition is handled.
74-
fn bytes(self) -> Bytes<Self>;
74+
fn bytes(self) -> ByteIterator<Self>;
7575

7676
}
7777

@@ -349,30 +349,36 @@ impl<T: Reader> ReaderUtil for T {
349349
return buf;
350350
}
351351

352-
fn bytes(self) -> Bytes<T> {
353-
Bytes{reader: self}
352+
fn bytes(self) -> ByteIterator<T> {
353+
ByteIterator{reader: self}
354354
}
355355
}
356356

357357
/// An iterator that reads a single byte on each iteration,
358-
/// until EOF.
358+
/// until `.read_byte()` returns `None`.
359+
///
360+
/// # Notes about the Iteration Protocol
361+
///
362+
/// The `ByteIterator` may yield `None` and thus terminate
363+
/// an iteration, but continue to yield elements if iteration
364+
/// is attempted again.
359365
///
360366
/// # Failure
361367
///
362368
/// Raises the same conditions as the `read` method, for
363369
/// each call to its `.next()` method.
364-
/// Ends the iteration if the condition is handled.
365-
pub struct Bytes<T> {
370+
/// Yields `None` if the condition is handled.
371+
pub struct ByteIterator<T> {
366372
priv reader: T,
367373
}
368374

369-
impl<R> Decorator<R> for Bytes<R> {
375+
impl<R> Decorator<R> for ByteIterator<R> {
370376
fn inner(self) -> R { self.reader }
371377
fn inner_ref<'a>(&'a self) -> &'a R { &self.reader }
372378
fn inner_mut_ref<'a>(&'a mut self) -> &'a mut R { &mut self.reader }
373379
}
374380

375-
impl<'self, R: Reader> Iterator<u8> for Bytes<R> {
381+
impl<'self, R: Reader> Iterator<u8> for ByteIterator<R> {
376382
#[inline]
377383
fn next(&mut self) -> Option<u8> {
378384
self.reader.read_byte()

0 commit comments

Comments
 (0)