@@ -99,9 +99,10 @@ pub trait Iterator<A> {
99
99
/// Advance the iterator and return the next value. Return `None` when the end is reached.
100
100
fn next ( & mut self ) -> Option < A > ;
101
101
102
- /// Return a lower bound and upper bound on the remaining length of the iterator.
102
+ /// Returns a lower and upper bound on the remaining length of the iterator.
103
103
///
104
- /// The common use case for the estimate is pre-allocating space to store the results.
104
+ /// An upper bound of `None` means either there is no known upper bound, or the upper bound
105
+ /// does not fit within a `uint`.
105
106
#[ inline]
106
107
fn size_hint ( & self ) -> ( uint , Option < uint > ) { ( 0 , None ) }
107
108
@@ -644,6 +645,9 @@ pub trait Iterator<A> {
644
645
}
645
646
646
647
/// A range iterator able to yield elements from both ends
648
+ ///
649
+ /// A `DoubleEndedIterator` can be thought of as a deque in that `next()` and `next_back()` exhaust
650
+ /// elements from the *same* range, and do not work independently of each other.
647
651
pub trait DoubleEndedIterator < A > : Iterator < A > {
648
652
/// Yield an element from the end of the range, returning `None` if the range is empty.
649
653
fn next_back ( & mut self ) -> Option < A > ;
@@ -690,12 +694,15 @@ impl<'a, A, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T
690
694
/// An object implementing random access indexing by `uint`
691
695
///
692
696
/// A `RandomAccessIterator` should be either infinite or a `DoubleEndedIterator`.
697
+ /// Calling `next()` or `next_back()` on a `RandomAccessIterator`
698
+ /// reduces the indexable range accordingly. That is, `it.idx(1)` will become `it.idx(0)`
699
+ /// after `it.next()` is called.
693
700
pub trait RandomAccessIterator < A > : Iterator < A > {
694
701
/// Return the number of indexable elements. At most `std::uint::MAX`
695
702
/// elements are indexable, even if the iterator represents a longer range.
696
703
fn indexable ( & self ) -> uint ;
697
704
698
- /// Return an element at an index
705
+ /// Return an element at an index, or `None` if the index is out of bounds
699
706
fn idx ( & mut self , index : uint ) -> Option < A > ;
700
707
}
701
708
0 commit comments