about summary refs log tree commit diff
path: root/src/libcore
diff options
context:
space:
mode:
authorCorey Richardson <corey@octayn.net>2014-12-05 10:06:41 -0800
committerCorey Richardson <corey@octayn.net>2014-12-05 10:06:41 -0800
commit9525af74a795532eb3ef789beac86cc5c783f344 (patch)
treef6e4a994f6dd09e5721cacfa0b1d561c5877012e /src/libcore
parent08ce178866e4533d8815fe5868a520e0fc55b21c (diff)
parentddb77185d36985aeac85094cb4742da93a7e821d (diff)
downloadrust-9525af74a795532eb3ef789beac86cc5c783f344.tar.gz
rust-9525af74a795532eb3ef789beac86cc5c783f344.zip
rollup merge of #19359: japaric/clone-cow
Now we can use `#[deriving(Clone)]` on structs that contain `Cow`.

r? @aturon or anyone else
Diffstat (limited to 'src/libcore')
-rw-r--r--src/libcore/borrow.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/libcore/borrow.rs b/src/libcore/borrow.rs
index b88fb914dd8..b44b87bd938 100644
--- a/src/libcore/borrow.rs
+++ b/src/libcore/borrow.rs
@@ -137,6 +137,18 @@ pub enum Cow<'a, T, Sized? B: 'a> where B: ToOwned<T> {
     Owned(T)
 }
 
+impl<'a, T, Sized? B> Clone for Cow<'a, T, B> where B: ToOwned<T> {
+    fn clone(&self) -> Cow<'a, T, B> {
+        match *self {
+            Borrowed(b) => Borrowed(b),
+            Owned(ref o) => {
+                let b: &B = BorrowFrom::borrow_from(o);
+                Owned(b.to_owned())
+            },
+        }
+    }
+}
+
 impl<'a, T, Sized? B> Cow<'a, T, B> where B: ToOwned<T> {
     /// Acquire a mutable reference to the owned form of the data.
     ///