From 8e6ae19bb51c6248384889670830fc7838617c33 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Wed, 30 Nov 2016 09:44:33 -0800 Subject: [PATCH] Add cloned example for Option --- src/libcore/option.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libcore/option.rs b/src/libcore/option.rs index 607e16887a831..8871e1fa840ef 100644 --- a/src/libcore/option.rs +++ b/src/libcore/option.rs @@ -659,6 +659,16 @@ impl Option { impl<'a, T: Clone> Option<&'a T> { /// Maps an `Option<&T>` to an `Option` 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 { self.map(|t| t.clone())