about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMara Bos <m-ou.se@m-ou.se>2019-05-30 12:49:54 +0200
committerMara Bos <m-ou.se@m-ou.se>2019-06-01 09:14:59 +0200
commitcb12460467aa98cb82587308341939679ff2a7d1 (patch)
tree9393faf6424c931a4c56bc92174cb68e350ff540
parentc28084ac16af4ab594b6860958df140e7c876a13 (diff)
downloadrust-cb12460467aa98cb82587308341939679ff2a7d1.tar.gz
rust-cb12460467aa98cb82587308341939679ff2a7d1.zip
Implement Clone::clone_from for Option.
-rw-r--r--src/libcore/option.rs21
1 files changed, 20 insertions, 1 deletions
diff --git a/src/libcore/option.rs b/src/libcore/option.rs
index 6b7f491effb..c75ecb059e8 100644
--- a/src/libcore/option.rs
+++ b/src/libcore/option.rs
@@ -145,7 +145,7 @@ use crate::pin::Pin;
 // which basically means it must be `Option`.
 
 /// The `Option` type. See [the module level documentation](index.html) for more.
-#[derive(Clone, Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
+#[derive(Copy, PartialEq, PartialOrd, Eq, Ord, Debug, Hash)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub enum Option<T> {
     /// No value
@@ -1041,6 +1041,25 @@ fn expect_failed(msg: &str) -> ! {
 /////////////////////////////////////////////////////////////////////////////
 
 #[stable(feature = "rust1", since = "1.0.0")]
+impl<T: Clone> Clone for Option<T> {
+    #[inline]
+    fn clone(&self) -> Self {
+        match self {
+            Some(x) => Some(x.clone()),
+            None => None,
+        }
+    }
+
+    #[inline]
+    fn clone_from(&mut self, source: &Self) {
+        match (self, source) {
+            (Some(to), Some(from)) => to.clone_from(from),
+            (to, from) => *to = from.clone(),
+        }
+    }
+}
+
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> Default for Option<T> {
     /// Returns [`None`][Option::None].
     #[inline]