Skip to content

Commit a449bc3

Browse files
authored
Rollup merge of rust-lang#61237 - DevQps:expand-iterator-docs, r=Mark-Simulacrum
Updated the Iterator docs with information about overriding methods. # Description Updated the Iterator docs with information about overriding methods. closes rust-lang#60223
2 parents 460e626 + b560b9c commit a449bc3

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/libcore/iter/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,11 @@
140140
//! call `next()` on your iterator, until it reaches `None`. Let's go over that
141141
//! next.
142142
//!
143+
//! Also note that `Iterator` provides a default implementation of methods such as `nth` and `fold`
144+
//! which call `next` internally. However, it is also possible to write a custom implementation of
145+
//! methods like `nth` and `fold` if an iterator can compute them more efficiently without calling
146+
//! `next`.
147+
//!
143148
//! # for Loops and IntoIterator
144149
//!
145150
//! Rust's `for` loop syntax is actually sugar for iterators. Here's a basic

src/libcore/iter/traits/iterator.rs

+1
Original file line numberDiff line numberDiff line change
@@ -964,6 +964,7 @@ pub trait Iterator {
964964
/// Creates an iterator that skips the first `n` elements.
965965
///
966966
/// After they have been consumed, the rest of the elements are yielded.
967+
/// Rather than overriding this method directly, instead override the `nth` method.
967968
///
968969
/// # Examples
969970
///

0 commit comments

Comments
 (0)