Skip to content

Commit

Permalink
Rollup merge of rust-lang#44668 - iwillspeak:into-iterator-docs, r=st…
Browse files Browse the repository at this point in the history
…eveklabnik

Add Example of `IntoIterator` as Trait Bound to Docs

Part of rust-lang#44600.
  • Loading branch information
alexcrichton authored Sep 18, 2017
2 parents 8f998d3 + ebd0e4f commit 196e8ae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/libcore/iter/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 196e8ae

Please sign in to comment.