From b560b9cd363d5b35d7f468d1749cab94380f7c62 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 27 May 2019 16:17:39 +0200 Subject: [PATCH] Updated the Iterator docs with information about overriding methods. --- src/libcore/iter/mod.rs | 5 +++++ src/libcore/iter/traits/iterator.rs | 1 + 2 files changed, 6 insertions(+) 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 403f3358105..062a7f7043d 100644 --- a/src/libcore/iter/traits/iterator.rs +++ b/src/libcore/iter/traits/iterator.rs @@ -964,6 +964,7 @@ fn take_while

(self, predicate: P) -> TakeWhile where /// 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 /// -- 2.44.0