Skip to content

Commit e9946f9

Browse files
committed
Override clone_from for {BinaryHeap, String}
CC #28481
1 parent 2a6f6f2 commit e9946f9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

src/libcollections/binary_heap.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,22 @@ use vec::{self, Vec};
167167
/// item's ordering relative to any other item, as determined by the `Ord`
168168
/// trait, changes while it is in the heap. This is normally only possible
169169
/// through `Cell`, `RefCell`, global state, I/O, or unsafe code.
170-
#[derive(Clone)]
171170
#[stable(feature = "rust1", since = "1.0.0")]
172171
pub struct BinaryHeap<T> {
173172
data: Vec<T>,
174173
}
175174

175+
#[stable(feature = "rust1", since = "1.0.0")]
176+
impl<T: Clone> Clone for BinaryHeap<T> {
177+
fn clone(&self) -> Self {
178+
BinaryHeap { data: self.data.clone() }
179+
}
180+
181+
fn clone_from(&mut self, source: &Self) {
182+
self.data.clone_from(&source.data);
183+
}
184+
}
185+
176186
#[stable(feature = "rust1", since = "1.0.0")]
177187
impl<T: Ord> Default for BinaryHeap<T> {
178188
#[inline]

src/libcollections/string.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ use vec::Vec;
3030
use boxed::Box;
3131

3232
/// A growable string stored as a UTF-8 encoded buffer.
33-
#[derive(Clone, PartialOrd, Eq, Ord)]
33+
#[derive(PartialOrd, Eq, Ord)]
3434
#[stable(feature = "rust1", since = "1.0.0")]
3535
pub struct String {
3636
vec: Vec<u8>,
@@ -765,6 +765,17 @@ impl fmt::Display for FromUtf16Error {
765765
}
766766
}
767767

768+
#[stable(feature = "rust1", since = "1.0.0")]
769+
impl Clone for String {
770+
fn clone(&self) -> Self {
771+
String { vec: self.vec.clone() }
772+
}
773+
774+
fn clone_from(&mut self, source: &Self) {
775+
self.vec.clone_from(&source.vec);
776+
}
777+
}
778+
768779
#[stable(feature = "rust1", since = "1.0.0")]
769780
impl FromIterator<char> for String {
770781
fn from_iter<I: IntoIterator<Item=char>>(iterable: I) -> String {

0 commit comments

Comments
 (0)