Skip to content

Commit 7b480cd

Browse files
committed
Implement Clone::clone_from for LinkedList
1 parent 702b45e commit 7b480cd

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/liballoc/collections/linked_list.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,19 @@ impl<T: Clone> Clone for LinkedList<T> {
11971197
fn clone(&self) -> Self {
11981198
self.iter().cloned().collect()
11991199
}
1200+
1201+
fn clone_from(&mut self, other: &Self) {
1202+
let mut iter_other = other.iter();
1203+
if self.len() > other.len() {
1204+
self.split_off(other.len());
1205+
}
1206+
for elem in self.iter_mut() {
1207+
elem.clone_from(iter_other.next().unwrap());
1208+
}
1209+
if !iter_other.is_empty() {
1210+
self.extend(iter_other.cloned());
1211+
}
1212+
}
12001213
}
12011214

12021215
#[stable(feature = "rust1", since = "1.0.0")]

0 commit comments

Comments
 (0)