We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
IntoIterator
1 parent caad256 commit ebd0e4fCopy full SHA for ebd0e4f
src/libcore/iter/traits.rs
@@ -196,6 +196,23 @@ pub trait FromIterator<A>: Sized {
196
/// assert_eq!(i as i32, n);
197
/// }
198
/// ```
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
+/// ```
216
#[stable(feature = "rust1", since = "1.0.0")]
217
pub trait IntoIterator {
218
/// The type of the elements being iterated over.
0 commit comments