Skip to content

Commit 8e851d3

Browse files
author
Rob Speer
authored
Fix a misleading statement in Iterator.nth()
The `Iterator.nth()` documentation says "Note that all preceding elements will be consumed". I assumed from that that the preceding elements would be the *only* ones that were consumed, but in fact the returned element is consumed as well. The way I read the documentation, I assumed that `nth(0)` would not discard anything (as there are 0 preceding elements), so I added a sentence clarifying that it does. I also rephrased it to avoid the stunted "i.e." phrasing.
1 parent 74c42ac commit 8e851d3

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libcore/iter/iterator.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,10 @@ pub trait Iterator {
209209

210210
/// Returns the `n`th element of the iterator.
211211
///
212-
/// Note that all preceding elements will be consumed (i.e. discarded).
212+
/// Note that all preceding elements, as well as the returned element, will be
213+
/// consumed. That means that the preceding elements will be discarded, and also
214+
/// that calling `nth(0)` multiple times on the same iterator will return different
215+
/// objects.
213216
///
214217
/// Like most indexing operations, the count starts from zero, so `nth(0)`
215218
/// returns the first value, `nth(1)` the second, and so on.

0 commit comments

Comments
 (0)