diff options
| author | Charles Gleason <charles_gleason@alumni.brown.edu> | 2019-10-01 18:20:46 -0400 |
|---|---|---|
| committer | Charles Gleason <charles_gleason@alumni.brown.edu> | 2019-10-01 18:23:08 -0400 |
| commit | 7b480cdec6d6c046dc3cd86020f3762e37558cd4 (patch) | |
| tree | 7ebc97c83eb1fd7f806f07744d560c197711d528 /src/liballoc/collections | |
| parent | 702b45e409495a41afcccbe87a251a692b0cefab (diff) | |
| download | rust-7b480cdec6d6c046dc3cd86020f3762e37558cd4.tar.gz rust-7b480cdec6d6c046dc3cd86020f3762e37558cd4.zip | |
Implement Clone::clone_from for LinkedList
Diffstat (limited to 'src/liballoc/collections')
| -rw-r--r-- | src/liballoc/collections/linked_list.rs | 13 |
1 files changed, 13 insertions, 0 deletions
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<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")] |
