Skip to content

Commit c4209d1

Browse files
committed
auto merge of rust-lang#15897 : Gankro/rust/it-docs, r=kballard
I found these things to be ambiguous, or at least worth stating explicitly to reduce the amount a user/developer needs to think about the API.
2 parents 217f1fb + 7b83600 commit c4209d1

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/libcore/iter.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ pub trait Iterator<A> {
9999
/// Advance the iterator and return the next value. Return `None` when the end is reached.
100100
fn next(&mut self) -> Option<A>;
101101

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.
103103
///
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`.
105106
#[inline]
106107
fn size_hint(&self) -> (uint, Option<uint>) { (0, None) }
107108

@@ -644,6 +645,9 @@ pub trait Iterator<A> {
644645
}
645646

646647
/// 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.
647651
pub trait DoubleEndedIterator<A>: Iterator<A> {
648652
/// Yield an element from the end of the range, returning `None` if the range is empty.
649653
fn next_back(&mut self) -> Option<A>;
@@ -690,12 +694,15 @@ impl<'a, A, T: DoubleEndedIterator<&'a mut A>> MutableDoubleEndedIterator for T
690694
/// An object implementing random access indexing by `uint`
691695
///
692696
/// 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.
693700
pub trait RandomAccessIterator<A>: Iterator<A> {
694701
/// Return the number of indexable elements. At most `std::uint::MAX`
695702
/// elements are indexable, even if the iterator represents a longer range.
696703
fn indexable(&self) -> uint;
697704

698-
/// Return an element at an index
705+
/// Return an element at an index, or `None` if the index is out of bounds
699706
fn idx(&mut self, index: uint) -> Option<A>;
700707
}
701708

0 commit comments

Comments
 (0)