From ebd0e4f1996053c1d63709b169682ee8586ae65f Mon Sep 17 00:00:00 2001 From: Will Speak Date: Mon, 18 Sep 2017 07:38:32 +0100 Subject: [PATCH] Add Example of `IntoIterator` as Trait Bound to Docs Part of #44600. --- src/libcore/iter/traits.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/libcore/iter/traits.rs b/src/libcore/iter/traits.rs index 2af129a67bddf..7ef50396c82bf 100644 --- a/src/libcore/iter/traits.rs +++ b/src/libcore/iter/traits.rs @@ -196,6 +196,23 @@ pub trait FromIterator: 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(collection: T) -> Vec +/// 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.