about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-09-18 11:04:27 -0500
committerGitHub <noreply@github.com>2017-09-18 11:04:27 -0500
commit4af3073c71c0a33df6b45eddd9bead9c80cbe994 (patch)
treece508a5c36762381eef605f94d0e06a3f2705dd2
parent3bbe15376c6e77d2a17b2261cdb503bf0bbbbbf4 (diff)
parentebd0e4f1996053c1d63709b169682ee8586ae65f (diff)
downloadrust-4af3073c71c0a33df6b45eddd9bead9c80cbe994.tar.gz
rust-4af3073c71c0a33df6b45eddd9bead9c80cbe994.zip
Rollup merge of #44668 - iwillspeak:into-iterator-docs, r=steveklabnik
Add Example of `IntoIterator` as Trait Bound to Docs

Part of #44600.
-rw-r--r--src/libcore/iter/traits.rs17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs
index 2af129a67bd..7ef50396c82 100644
--- a/src/libcore/iter/traits.rs
+++ b/src/libcore/iter/traits.rs
@@ -196,6 +196,23 @@ pub trait FromIterator<A>: Sized {
 ///     assert_eq!(i as i32, n);
 /// }
 /// ```
+///
+/// It is common to use `IntoIterator` as a trait bound. This allows
+/// the input collection type to change, so long as it is still an
+/// iterator. Additional bounds can be specified by restricting on
+/// `Item`:
+///
+/// ```rust
+/// fn collect_as_strings<T>(collection: T) -> Vec<String>
+///     where T: IntoIterator,
+///           T::Item : std::fmt::Debug,
+/// {
+///     collection
+///         .into_iter()
+///         .map(|item| format!("{:?}", item))
+///         .collect()
+/// }
+/// ```
 #[stable(feature = "rust1", since = "1.0.0")]
 pub trait IntoIterator {
     /// The type of the elements being iterated over.