about summary refs log tree commit diff
path: root/src/libstd/collections
diff options
context:
space:
mode:
authorHuon Wilson <dbau.pp+github@gmail.com>2014-12-30 21:01:36 +1100
committerHuon Wilson <dbau.pp+github@gmail.com>2014-12-30 21:01:36 +1100
commitb7832ed0b42a2d6512e3f8d09605986237f02ed5 (patch)
tree313e9f72ae737775db85764279a79122f4d8b458 /src/libstd/collections
parentfea5aa656ff4349f4d3e1fea1447d26986762ae1 (diff)
downloadrust-b7832ed0b42a2d6512e3f8d09605986237f02ed5.tar.gz
rust-b7832ed0b42a2d6512e3f8d09605986237f02ed5.zip
Implement `Clone` for a large number of iterators & other adaptors.
It's useful to be able to save state.
Diffstat (limited to 'src/libstd/collections')
-rw-r--r--src/libstd/collections/hash/map.rs27
-rw-r--r--src/libstd/collections/hash/table.rs23
2 files changed, 50 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index d749cd77cef..c095ebe4f65 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1309,6 +1309,15 @@ pub struct Entries<'a, K: 'a, V: 'a> {
     inner: table::Entries<'a, K, V>
 }
 
+// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
+impl<'a, K, V> Clone for Entries<'a, K, V> {
+    fn clone(&self) -> Entries<'a, K, V> {
+        Entries {
+            inner: self.inner.clone()
+        }
+    }
+}
+
 /// HashMap mutable values iterator
 pub struct IterMut<'a, K: 'a, V: 'a> {
     inner: table::IterMut<'a, K, V>
@@ -1329,11 +1338,29 @@ pub struct Keys<'a, K: 'a, V: 'a> {
     inner: Map<(&'a K, &'a V), &'a K, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a K>
 }
 
+// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
+impl<'a, K, V> Clone for Keys<'a, K, V> {
+    fn clone(&self) -> Keys<'a, K, V> {
+        Keys {
+            inner: self.inner.clone()
+        }
+    }
+}
+
 /// HashMap values iterator
 pub struct Values<'a, K: 'a, V: 'a> {
     inner: Map<(&'a K, &'a V), &'a V, Entries<'a, K, V>, fn((&'a K, &'a V)) -> &'a V>
 }
 
+// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
+impl<'a, K, V> Clone for Values<'a, K, V> {
+    fn clone(&self) -> Values<'a, K, V> {
+        Values {
+            inner: self.inner.clone()
+        }
+    }
+}
+
 /// HashMap drain iterator
 pub struct Drain<'a, K: 'a, V: 'a> {
     inner: iter::Map<
diff --git a/src/libstd/collections/hash/table.rs b/src/libstd/collections/hash/table.rs
index 3ae3a8ffbad..3f5047cf748 100644
--- a/src/libstd/collections/hash/table.rs
+++ b/src/libstd/collections/hash/table.rs
@@ -718,6 +718,18 @@ struct RawBuckets<'a, K, V> {
     marker: marker::ContravariantLifetime<'a>,
 }
 
+// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
+impl<'a, K, V> Clone for RawBuckets<'a, K, V> {
+    fn clone(&self) -> RawBuckets<'a, K, V> {
+        RawBuckets {
+            raw: self.raw,
+            hashes_end: self.hashes_end,
+            marker: marker::ContravariantLifetime,
+        }
+    }
+}
+
+
 impl<'a, K, V> Iterator<RawBucket<K, V>> for RawBuckets<'a, K, V> {
     fn next(&mut self) -> Option<RawBucket<K, V>> {
         while self.raw.hash != self.hashes_end {
@@ -775,6 +787,17 @@ pub struct Entries<'a, K: 'a, V: 'a> {
     elems_left: uint,
 }
 
+// FIXME(#19839) Remove in favor of `#[deriving(Clone)]`
+impl<'a, K, V> Clone for Entries<'a, K, V> {
+    fn clone(&self) -> Entries<'a, K, V> {
+        Entries {
+            iter: self.iter.clone(),
+            elems_left: self.elems_left
+        }
+    }
+}
+
+
 /// Iterator over mutable references to entries in a table.
 pub struct IterMut<'a, K: 'a, V: 'a> {
     iter: RawBuckets<'a, K, V>,