File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -1009,8 +1009,19 @@ pub trait Iterator {
1009
1009
( ts, us)
1010
1010
}
1011
1011
1012
- /// Creates an iterator that clones the elements it yields. Useful for
1013
- /// converting an Iterator<&T> to an Iterator<T>.
1012
+ /// Creates an iterator that clones the elements it yields.
1013
+ ///
1014
+ /// This is useful for converting an Iterator<&T> to an Iterator<T>,
1015
+ /// so it's a more convenient form of `map(|&x| x)`.
1016
+ ///
1017
+ /// # Examples
1018
+ ///
1019
+ /// ```
1020
+ /// let a = [0, 1, 2];
1021
+ /// let v_cloned: Vec<_> = a.iter().cloned().collect();
1022
+ /// let v_map: Vec<_> = a.iter().map(|&x| x).collect();
1023
+ /// assert_eq!(v_cloned, v_map);
1024
+ /// ```
1014
1025
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1015
1026
fn cloned < ' a , T : ' a > ( self ) -> Cloned < Self >
1016
1027
where Self : Sized + Iterator < Item =& ' a T > , T : Clone
You can’t perform that action at this time.
0 commit comments