File tree 1 file changed +21
-0
lines changed
1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -1017,6 +1017,27 @@ impl<'a, I: Iterator + ?Sized> Iterator for &'a mut I {
1017
1017
built from an iterator over elements of type `{A}`"]
1018
1018
pub trait FromIterator < A > {
1019
1019
/// Build a container with elements from something iterable.
1020
+ ///
1021
+ /// # Examples
1022
+ ///
1023
+ /// ```
1024
+ /// use std::collections::HashSet;
1025
+ /// use std::iter::FromIterator;
1026
+ ///
1027
+ /// let colors_vec = vec!["red", "red", "yellow", "blue"];
1028
+ /// let colors_set = HashSet::<&str>::from_iter(colors_vec);
1029
+ /// assert_eq!(colors_set.len(), 3);
1030
+ /// ```
1031
+ ///
1032
+ /// `FromIterator` is more commonly used implicitly via the `Iterator::collect` method:
1033
+ ///
1034
+ /// ```
1035
+ /// use std::collections::HashSet;
1036
+ ///
1037
+ /// let colors_vec = vec!["red", "red", "yellow", "blue"];
1038
+ /// let colors_set = colors_vec.into_iter().collect::<HashSet<&str>>();
1039
+ /// assert_eq!(colors_set.len(), 3);
1040
+ /// ```
1020
1041
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1021
1042
fn from_iter < T : IntoIterator < Item =A > > ( iterator : T ) -> Self ;
1022
1043
}
You can’t perform that action at this time.
0 commit comments