about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-30 16:26:15 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-30 16:26:15 -0800
commita8820f7a2df1932918dbaa5d123486d86f7fb008 (patch)
treee4d6d36b5710f4b707472017c823aefb14cfd960 /src/libstd
parent899eb65b29bf666b05b155a3d4cc6002ac8cb26a (diff)
parentb7832ed0b42a2d6512e3f8d09605986237f02ed5 (diff)
downloadrust-a8820f7a2df1932918dbaa5d123486d86f7fb008.tar.gz
rust-a8820f7a2df1932918dbaa5d123486d86f7fb008.zip
rollup merge of #20328: huonw/attack-of-the-clones
It's useful to be able to save state.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/c_str.rs2
-rw-r--r--src/libstd/collections/hash/map.rs27
-rw-r--r--src/libstd/collections/hash/table.rs23
-rw-r--r--src/libstd/io/fs.rs1
-rw-r--r--src/libstd/io/util.rs2
5 files changed, 55 insertions, 0 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs
index f28abcc10cf..8dbaab564ba 100644
--- a/src/libstd/c_str.rs
+++ b/src/libstd/c_str.rs
@@ -486,6 +486,8 @@ fn check_for_null(v: &[u8], buf: *mut libc::c_char) {
 /// External iterator for a CString's bytes.
 ///
 /// Use with the `std::iter` module.
+#[allow(raw_pointer_deriving)]
+#[deriving(Clone)]
 pub struct CChars<'a> {
     ptr: *const libc::c_char,
     marker: marker::ContravariantLifetime<'a>,
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs
index b473a665c76..8181ea5253f 100644
--- a/src/libstd/collections/hash/map.rs
+++ b/src/libstd/collections/hash/map.rs
@@ -1319,6 +1319,15 @@ pub struct Iter<'a, K: 'a, V: 'a> {
     inner: table::Iter<'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>
@@ -1339,11 +1348,29 @@ pub struct Keys<'a, K: 'a, V: 'a> {
     inner: Map<(&'a K, &'a V), &'a K, Iter<'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, Iter<'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 f76b8ac3326..f5fbfcabcfb 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 Iter<'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>,
diff --git a/src/libstd/io/fs.rs b/src/libstd/io/fs.rs
index caa6590bb28..e4c31ff8dd3 100644
--- a/src/libstd/io/fs.rs
+++ b/src/libstd/io/fs.rs
@@ -558,6 +558,7 @@ pub fn walk_dir(path: &Path) -> IoResult<Directories> {
 }
 
 /// An iterator that walks over a directory
+#[deriving(Clone)]
 pub struct Directories {
     stack: Vec<Path>,
 }
diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs
index 90d7c1388a1..2a98067c970 100644
--- a/src/libstd/io/util.rs
+++ b/src/libstd/io/util.rs
@@ -163,6 +163,7 @@ impl Writer for MultiWriter {
 
 /// A `Reader` which chains input from multiple `Reader`s, reading each to
 /// completion before moving onto the next.
+#[deriving(Clone)]
 pub struct ChainedReader<I, R> {
     readers: I,
     cur_reader: Option<R>,
@@ -246,6 +247,7 @@ pub fn copy<R: Reader, W: Writer>(r: &mut R, w: &mut W) -> io::IoResult<()> {
 }
 
 /// An adaptor converting an `Iterator<u8>` to a `Reader`.
+#[deriving(Clone)]
 pub struct IterReader<T> {
     iter: T,
 }