Implement Clone::clone_from for LinkedList
This commit is contained in:
parent
702b45e409
commit
7b480cdec6
1 changed files with 13 additions and 0 deletions
|
|
@ -1197,6 +1197,19 @@ impl<T: Clone> Clone for LinkedList<T> {
|
|||
fn clone(&self) -> Self {
|
||||
self.iter().cloned().collect()
|
||||
}
|
||||
|
||||
fn clone_from(&mut self, other: &Self) {
|
||||
let mut iter_other = other.iter();
|
||||
if self.len() > other.len() {
|
||||
self.split_off(other.len());
|
||||
}
|
||||
for elem in self.iter_mut() {
|
||||
elem.clone_from(iter_other.next().unwrap());
|
||||
}
|
||||
if !iter_other.is_empty() {
|
||||
self.extend(iter_other.cloned());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue