]> git.lizzy.rs Git - rust.git/commitdiff
Manual Clone for Windows/Chunks.
authorHuon Wilson <dbau.pp+github@gmail.com>
Mon, 2 Mar 2015 06:50:47 +0000 (17:50 +1100)
committerHuon Wilson <dbau.pp+github@gmail.com>
Mon, 2 Mar 2015 06:54:18 +0000 (17:54 +1100)
`#[derive(Clone)]` unnecessarily requires the element type to also be
`Clone`.

src/libcore/slice.rs

index 5b78da34eddde0e7dd363383b3fd0d4b719c5640..f99cfbaab5d702570e42723709e48cefaf9aeb9a 100644 (file)
@@ -1167,13 +1167,23 @@ fn size_hint(&self) -> (usize, Option<usize>) {
 forward_iterator! { RSplitNMut: T, &'a mut [T] }
 
 /// An iterator over overlapping subslices of length `size`.
-#[derive(Clone)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Windows<'a, T:'a> {
     v: &'a [T],
     size: usize
 }
 
+// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a, T> Clone for Windows<'a, T> {
+    fn clone(&self) -> Windows<'a, T> {
+        Windows {
+            v: self.v,
+            size: self.size,
+        }
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T> Iterator for Windows<'a, T> {
     type Item = &'a [T];
@@ -1239,13 +1249,23 @@ fn idx(&mut self, index: usize) -> Option<&'a [T]> {
 ///
 /// When the slice len is not evenly divided by the chunk size, the last slice
 /// of the iteration will be the remainder.
-#[derive(Clone)]
 #[stable(feature = "rust1", since = "1.0.0")]
 pub struct Chunks<'a, T:'a> {
     v: &'a [T],
     size: usize
 }
 
+// FIXME(#19839) Remove in favor of `#[derive(Clone)]`
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a, T> Clone for Chunks<'a, T> {
+    fn clone(&self) -> Chunks<'a, T> {
+        Chunks {
+            v: self.v,
+            size: self.size,
+        }
+    }
+}
+
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T> Iterator for Chunks<'a, T> {
     type Item = &'a [T];