about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-03-29 16:54:40 +0000
committerbors <bors@rust-lang.org>2015-03-29 16:54:40 +0000
commitc5370be36ec6601c4a816f0341d1acd81e08d345 (patch)
tree9a81221fecc4ce54039f6c7d2f8bbd87018f993e /src
parentb27ba527c5cee06f43967daf3a0dd01a2258a0fa (diff)
parent8fe7f1fa97884c233eb4b8128197431a9b1506ed (diff)
Auto merge of #23816 - frewsxcv:fromiterator-example, r=Manishearth
Diffstat (limited to 'src')
-rw-r--r--src/libcore/iter.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index bb057c553db..39bf97ae1ce 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -1017,6 +1017,27 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
                           built from an iterator over elements of type `{A}`"]
 pub trait FromIterator<A> {
     /// Build a container with elements from something iterable.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// use std::collections::HashSet;
+    /// use std::iter::FromIterator;
+    ///
+    /// let colors_vec = vec!["red", "red", "yellow", "blue"];
+    /// let colors_set = HashSet::<&str>::from_iter(colors_vec);
+    /// assert_eq!(colors_set.len(), 3);
+    /// ```
+    ///
+    /// `FromIterator` is more commonly used implicitly via the `Iterator::collect` method:
+    ///
+    /// ```
+    /// use std::collections::HashSet;
+    ///
+    /// let colors_vec = vec!["red", "red", "yellow", "blue"];
+    /// let colors_set = colors_vec.into_iter().collect::<HashSet<&str>>();
+    /// assert_eq!(colors_set.len(), 3);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     fn from_iter<T: IntoIterator<Item=A>>(iterator: T) -> Self;
 }