Skip to content

Commit 570f858

Browse files
authored
Rollup merge of rust-lang#39174 - rspeer:iter-nth-doc-fix, r=alexcrichton
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 (there are 0 preceding elements, and maybe it just peeks at the start of the iterator somehow), so I added a sentence clarifying that it does. I also rephrased it to avoid the stunted "i.e." phrasing.
2 parents 064a0ee + 11d36ae commit 570f858

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/libcore/iter/iterator.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,14 @@ 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).
213-
///
214212
/// Like most indexing operations, the count starts from zero, so `nth(0)`
215213
/// returns the first value, `nth(1)` the second, and so on.
216214
///
215+
/// Note that all preceding elements, as well as the returned element, will be
216+
/// consumed from the iterator. That means that the preceding elements will be
217+
/// discarded, and also that calling `nth(0)` multiple times on the same iterator
218+
/// will return different elements.
219+
///
217220
/// `nth()` will return [`None`] if `n` is greater than or equal to the length of the
218221
/// iterator.
219222
///

0 commit comments

Comments
 (0)