File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -196,6 +196,23 @@ pub trait FromIterator<A>: Sized {
196196/// assert_eq!(i as i32, n);
197197/// }
198198/// ```
199+ ///
200+ /// It is common to use `IntoIterator` as a trait bound. This allows
201+ /// the input collection type to change, so long as it is still an
202+ /// iterator. Additional bounds can be specified by restricting on
203+ /// `Item`:
204+ ///
205+ /// ```rust
206+ /// fn collect_as_strings<T>(collection: T) -> Vec<String>
207+ /// where T: IntoIterator,
208+ /// T::Item : std::fmt::Debug,
209+ /// {
210+ /// collection
211+ /// .into_iter()
212+ /// .map(|item| format!("{:?}", item))
213+ /// .collect()
214+ /// }
215+ /// ```
199216#[ stable( feature = "rust1" , since = "1.0.0" ) ]
200217pub trait IntoIterator {
201218 /// The type of the elements being iterated over.
You can’t perform that action at this time.
0 commit comments