about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexis Beingessner <a.beingessner@gmail.com>2014-07-22 00:32:49 -0400
committerAlexis Beingessner <a.beingessner@gmail.com>2014-07-22 14:24:04 -0400
commit7b83600ea2da54c99bd048c37d59ca4a183c1bcd (patch)
tree25f3d133e0a1e4b9cbac7c5ca23a4278b9998e67
parentbfcde309e7748dfdf33418c2a1e6c6bdfbdcc8e2 (diff)
downloadrust-7b83600ea2da54c99bd048c37d59ca4a183c1bcd.tar.gz
rust-7b83600ea2da54c99bd048c37d59ca4a183c1bcd.zip
clarifying iterator trait documentation
-rw-r--r--src/libcore/iter.rs13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index 6ba0f7c3a15..7706d01cbae 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -99,9 +99,10 @@ pub trait Iterator<A> {
     /// Advance the iterator and return the next value. Return `None` when the end is reached.
     fn next(&mut self) -> Option<A>;
 
-    /// Return a lower bound and upper bound on the remaining length of the iterator.
+    /// Returns a lower and upper bound on the remaining length of the iterator.
     ///
-    /// The common use case for the estimate is pre-allocating space to store the results.
+    /// An upper bound of `None` means either there is no known upper bound, or the upper bound
+    /// does not fit within a `uint`.
     #[inline]
     fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
 
@@ -644,6 +645,9 @@ pub trait Iterator<A> {
 }
 
 /// A range iterator able to yield elements from both ends
+///
+/// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
+/// elements from the *same* range, and do not work independently of each other.
 pub trait DoubleEndedIterator<A>: Iterator<A> {
     /// Yield an element from the end of the range, returning `None` if the range is empty.
     fn next_back(&mut self) -> Option<A>;
@@ -690,12 +694,15 @@ impl<'a, A, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T
 /// An object implementing random access indexing by `uint`
 ///
 /// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
+/// Calling `next()` or `next_back()` on a `RandomAccessIterator`
+/// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)`
+/// after `it.next()` is called.
 pub trait RandomAccessIterator<A>: Iterator<A> {
     /// Return the number of indexable elements. At most `std::uint::MAX`
     /// elements are indexable, even if the iterator represents a longer range.
     fn indexable(&self) -> uint;
 
-    /// Return an element at an index
+    /// Return an element at an index, or `None` if the index is out of bounds
     fn idx(&mut self, index: uint) -> Option<A>;
 }