about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2016-12-03 15:39:53 -0500
committerGitHub <noreply@github.com>2016-12-03 15:39:53 -0500
commit6c327adca2aa66f3fc09faff8b2928c1b1542104 (patch)
treebd35c63bbe375f7e983a5f69aeb8f96d83756377
parentd0e57b19cf65cab46b8deff6c80aab679ceae43e (diff)
parent8e6ae19bb51c6248384889670830fc7838617c33 (diff)
downloadrust-6c327adca2aa66f3fc09faff8b2928c1b1542104.tar.gz
rust-6c327adca2aa66f3fc09faff8b2928c1b1542104.zip
Rollup merge of #38090 - GuillaumeGomez:option_doc, r=frewsxcv
Add cloned example for Option

r? @frewsxcv
-rw-r--r--src/libcore/option.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 607e16887a8..8871e1fa840 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -659,6 +659,16 @@ impl<T> Option<T> {
 impl<'a, T: Clone> Option<&'a T> {
     /// Maps an `Option<&T>` to an `Option<T>` by cloning the contents of the
     /// option.
+    ///
+    /// # Examples
+    ///
+    /// ```
+    /// let x = 12;
+    /// let opt_x = Some(&x);
+    /// assert_eq!(opt_x, Some(&12));
+    /// let cloned = opt_x.cloned();
+    /// assert_eq!(cloned, Some(12));
+    /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
     pub fn cloned(self) -> Option<T> {
         self.map(|t| t.clone())