about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-05-24 22:42:00 +0000
committerbors <bors@rust-lang.org>2015-05-24 22:42:00 +0000
commit893e4169337016cc5bbe4048f2132b896bda8ce8 (patch)
tree249548869c52bec43b780de75c7ad90dadffc5ae /src/libcore
parent820b1d83933d1a3ddcc18e6cfcfea91b6ee2eee6 (diff)
parent2d5d6fbca49c29287c29aa8194be79db6b7de89f (diff)
downloadrust-893e4169337016cc5bbe4048f2132b896bda8ce8.tar.gz
rust-893e4169337016cc5bbe4048f2132b896bda8ce8.zip
Auto merge of #25758 - tshepang:add-cloned-example, r=Gankro
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/iter.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/libcore/iter.rs b/src/libcore/iter.rs
index ed7cdbbb6e2..5042d44b288 100644
--- a/src/libcore/iter.rs
+++ b/src/libcore/iter.rs
@@ -1009,8 +1009,19 @@ pub trait Iterator {
         (ts, us)
     }
 
-    /// Creates an iterator that clones the elements it yields. Useful for
-    /// converting an Iterator<&T> to an Iterator<T>.
+    /// Creates an iterator that clones the elements it yields.
+    ///
+    /// This is useful for converting an Iterator<&T> to an Iterator<T>,
+    /// so it's a more convenient form of `map(|&x| x)`.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// let a = [0, 1, 2];
+    /// let v_cloned: Vec<_> = a.iter().cloned().collect();
+    /// let v_map: Vec<_> = a.iter().map(|&x| x).collect();
+    /// assert_eq!(v_cloned, v_map);
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     fn cloned<'a, T: 'a>(self) -> Cloned<Self>
         where Self: Sized + Iterator<Item=&'a T>, T: Clone