about summary refs log tree commit diff
path: root/src/libcore/option.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcore/option.rs')
-rw-r--r--src/libcore/option.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index af9efee0c8f..f05a681a526 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -150,6 +150,7 @@ use mem;
 use result::{Result, Ok, Err};
 use slice;
 use slice::AsSlice;
+use clone::Clone;
 
 // Note that this is not a lang item per se, but it has a hidden dependency on
 // `Iterator`, which is one. The compiler assumes that the `next` method of
@@ -691,6 +692,14 @@ 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<&T>.
+    #[unstable = "recently added as part of collections reform"]
+    pub fn cloned(self) -> Option<T> {
+        self.map(|t| t.clone())
+    }
+}
+
 impl<T: Default> Option<T> {
     /// Returns the contained value or a default
     ///