]> git.lizzy.rs Git - rust.git/commitdiff
Add cloned example for Option
authorGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 30 Nov 2016 17:44:33 +0000 (09:44 -0800)
committerGuillaume Gomez <guillaume1.gomez@gmail.com>
Wed, 30 Nov 2016 17:44:33 +0000 (09:44 -0800)
src/libcore/option.rs

index 607e16887a831b8faaa0fcb22a351ec481f5909d..8871e1fa840ef7cc6cc5b8a5593a785b23dca20b 100644 (file)
@@ -659,6 +659,16 @@ pub fn take(&mut self) -> 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())