From 7b480cdec6d6c046dc3cd86020f3762e37558cd4 Mon Sep 17 00:00:00 2001 From: Charles Gleason Date: Tue, 1 Oct 2019 18:20:46 -0400 Subject: Implement Clone::clone_from for LinkedList --- src/liballoc/collections/linked_list.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/liballoc') diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 816a71f2557..998bcb87393 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -1197,6 +1197,19 @@ impl Clone for LinkedList { 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")] -- cgit 1.4.1-3-g733a5