diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 16:18:27 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2015-03-31 16:18:27 -0700 |
| commit | 85e997adfffa5e8511ff31710649038216028832 (patch) | |
| tree | 2f8149fe5e446085734f4cecaf6563fd4b1ac75b | |
| parent | 66598656a5bb684479473235a64ea2b4f2fda0d2 (diff) | |
| parent | cf5616242a1d724a374e0da5f7e247765178a769 (diff) | |
| download | rust-85e997adfffa5e8511ff31710649038216028832.tar.gz rust-85e997adfffa5e8511ff31710649038216028832.zip | |
rollup merge of #23899: steveklabnik/gh23851
Conflicts: src/libcore/iter.rs
| -rw-r--r-- | src/libcore/iter.rs | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs index 1698c833298..cf417d9d2d8 100644 --- a/src/libcore/iter.rs +++ b/src/libcore/iter.rs @@ -26,23 +26,22 @@ //! in reverse, the `FromIterator` trait for creating a container from an //! iterator, and much more. //! -//! ## Rust's `for` loop +//! # Rust's `for` loop //! -//! The special syntax used by rust's `for` loop is based around the `Iterator` -//! trait defined in this module. For loops can be viewed as a syntactical -//! expansion into a `loop`, for example, the `for` loop in this example is -//! essentially translated to the `loop` below. +//! The special syntax used by rust's `for` loop is based around the +//! `IntoIterator` trait defined in this module. `for` loops can be viewed as a +//! syntactical expansion into a `loop`, for example, the `for` loop in this +//! example is essentially translated to the `loop` below. //! //! ``` //! let values = vec![1, 2, 3]; //! -//! // "Syntactical sugar" taking advantage of an iterator -//! for &x in values.iter() { +//! for x in values { //! println!("{}", x); //! } //! //! // Rough translation of the iteration without a `for` iterator. -//! let mut it = values.iter(); +//! let mut it = values.into_iter(); //! loop { //! match it.next() { //! Some(&x) => { @@ -53,7 +52,8 @@ //! } //! ``` //! -//! This `for` loop syntax can be applied to any iterator over any type. +//! Because `Iterator`s implement `IntoIterator`, this `for` loop syntax can be applied to any +//! iterator over any type. #![stable(feature = "rust1", since = "1.0.0")] @@ -1057,6 +1057,9 @@ pub trait FromIterator<A> { } /// Conversion into an `Iterator` +/// +/// Implementing this trait allows you to use your type with Rust's `for` loop. See +/// the [module level documentation](../index.html) for more details. #[stable(feature = "rust1", since = "1.0.0")] pub trait IntoIterator { /// The type of the elements being iterated |
