about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-05-28 11:49:00 +0200
committerGitHub <noreply@github.com>2019-05-28 11:49:00 +0200
commita449bc3ad0036094f8f615afe81df732c8551706 (patch)
treeb7db1e4ef4bf075c68b6513ece04f336165c5a71 /src
parent460e626a9cf5c2bec4dba8752de18aebae4c0c93 (diff)
parentb560b9cd363d5b35d7f468d1749cab94380f7c62 (diff)
Rollup merge of #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 #60223
Diffstat (limited to 'src')
-rw-r--r--src/libcore/iter/mod.rs5
-rw-r--r--src/libcore/iter/traits/iterator.rs1
2 files changed, 6 insertions, 0 deletions
diff --git a/src/libcore/iter/mod.rs b/src/libcore/iter/mod.rs
index 1601357d3b0..6eccb9d1ea8 100644
--- a/src/libcore/iter/mod.rs
+++ b/src/libcore/iter/mod.rs
@@ -140,6 +140,11 @@
 //! call `next()` on your iterator, until it reaches `None`. Let's go over that
 //! next.
 //!
+//! Also note that `Iterator` provides a default implementation of methods such as `nth` and `fold`
+//! which call `next` internally. However, it is also possible to write a custom implementation of
+//! methods like `nth` and `fold` if an iterator can compute them more efficiently without calling
+//! `next`.
+//!
 //! # for Loops and IntoIterator
 //!
 //! Rust's `for` loop syntax is actually sugar for iterators. Here's a basic
diff --git a/src/libcore/iter/traits/iterator.rs b/src/libcore/iter/traits/iterator.rs
index 38c7c9bc4d0..d0fdd79473e 100644
--- a/src/libcore/iter/traits/iterator.rs
+++ b/src/libcore/iter/traits/iterator.rs
@@ -964,6 +964,7 @@ pub trait Iterator {
     /// Creates an iterator that skips the first `n` elements.
     ///
     /// After they have been consumed, the rest of the elements are yielded.
+    /// Rather than overriding this method directly, instead override the `nth` method.
     ///
     /// # Examples
     ///