]> git.lizzy.rs Git - rust.git/commitdiff
Override `clone_from` for `{BinaryHeap, String}`
authorAndrew Paseltiner <apaseltiner@gmail.com>
Wed, 23 Sep 2015 12:49:50 +0000 (08:49 -0400)
committerAndrew Paseltiner <apaseltiner@gmail.com>
Wed, 23 Sep 2015 14:32:58 +0000 (10:32 -0400)
CC #28481

src/libcollections/binary_heap.rs
src/libcollections/string.rs

index a3e32b59b710de007c03d43b47f70e9f5b13bff6..b7afe9685778e0d0ac168731b6a0b394284d5061 100644 (file)
 /// item's ordering relative to any other item, as determined by the `Ord`
 /// trait, changes while it is in the heap. This is normally only possible
 /// through `Cell`, `RefCell`, global state, I/O, or unsafe code.
-#[derive(Clone)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct BinaryHeap<T> {
     data: Vec<T>,
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<T: Clone> Clone for BinaryHeap<T> {
+    fn clone(&self) -> Self {
+        BinaryHeap { data: self.data.clone() }
+    }
+
+    fn clone_from(&mut self, source: &Self) {
+        self.data.clone_from(&source.data);
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Ord> Default for BinaryHeap<T> {
     #[inline]
index bb65d7469ab14938ecb7021f7f93ec6a2b9c9e90..ba921fed68b1dc4e922c3cc7aa64f5153302c482 100644 (file)
@@ -30,7 +30,7 @@
 use boxed::Box;
 
 /// A growable string stored as a UTF-8 encoded buffer.
-#[derive(Clone, PartialOrd, Eq, Ord)]
+#[derive(PartialOrd, Eq, Ord)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct String {
     vec: Vec<u8>,
@@ -765,6 +765,17 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl Clone for String {
+    fn clone(&self) -> Self {
+        String { vec: self.vec.clone() }
+    }
+
+    fn clone_from(&mut self, source: &Self) {
+        self.vec.clone_from(&source.vec);
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl FromIterator<char> for String {
     fn from_iter<I: IntoIterator<Item=char>>(iterable: I) -> String {