diff --git a/src/binary_heap.rs b/src/binary_heap.rs index 54be51dd..3299f25e 100644 --- a/src/binary_heap.rs +++ b/src/binary_heap.rs @@ -412,6 +412,20 @@ impl<'a, T> Drop for Hole<'a, T> { } } +impl Clone for BinaryHeap +where + N: ArrayLength, + K: Kind, + T: Ord + Clone, +{ + fn clone(&self) -> Self { + Self { + _kind: self._kind, + data: self.data.clone(), + } + } +} + impl fmt::Debug for BinaryHeap where N: ArrayLength, diff --git a/src/indexmap.rs b/src/indexmap.rs index 6a472585..ed5b35e7 100644 --- a/src/indexmap.rs +++ b/src/indexmap.rs @@ -28,6 +28,7 @@ impl HashValue { } #[doc(hidden)] +#[derive(Clone)] pub struct Bucket { hash: HashValue, key: K, @@ -268,6 +269,20 @@ where } } +impl Clone for CoreMap +where + K: Eq + Hash + Clone, + V: Clone, + N: ArrayLength> + ArrayLength>, +{ + fn clone(&self) -> Self { + Self { + entries: self.entries.clone(), + indices: self.indices.clone(), + } + } +} + /// Fixed capacity [`IndexMap`](https://docs.rs/indexmap/1/indexmap/map/struct.IndexMap.html) /// /// Note that the capacity of the `IndexMap` must be a power of 2. @@ -725,6 +740,21 @@ where } } +impl Clone for IndexMap +where + K: Eq + Hash + Clone, + V: Clone, + S: Clone, + N: ArrayLength> + ArrayLength>, +{ + fn clone(&self) -> Self { + Self { + core: self.core.clone(), + build_hasher: self.build_hasher.clone(), + } + } +} + impl fmt::Debug for IndexMap where K: Eq + Hash + fmt::Debug, @@ -846,6 +876,18 @@ where } } +impl<'a, K, V> Clone for Iter<'a, K, V> +where + K: 'a, + V: 'a, +{ + fn clone(&self) -> Self { + Self { + iter: self.iter.clone(), + } + } +} + pub struct IterMut<'a, K, V> where K: 'a, diff --git a/src/indexset.rs b/src/indexset.rs index bd3de588..395c1ca5 100644 --- a/src/indexset.rs +++ b/src/indexset.rs @@ -454,6 +454,19 @@ where } } +impl Clone for IndexSet +where + T: Eq + Hash + Clone, + S: Clone, + N: ArrayLength> + ArrayLength>, +{ + fn clone(&self) -> Self { + Self { + map: self.map.clone(), + } + } +} + impl fmt::Debug for IndexSet where T: Eq + Hash + fmt::Debug, @@ -567,6 +580,17 @@ where } } +impl<'a, T> Clone for Iter<'a, T> +where + T: 'a, +{ + fn clone(&self) -> Self { + Self { + iter: self.iter.clone(), + } + } +} + pub struct Difference<'a, T, N, S> where S: 'a + BuildHasher, diff --git a/src/linear_map.rs b/src/linear_map.rs index f60bb033..123034c4 100644 --- a/src/linear_map.rs +++ b/src/linear_map.rs @@ -390,6 +390,19 @@ where } } +impl Clone for LinearMap +where + N: ArrayLength<(K, V)>, + K: Eq + Clone, + V: Clone, +{ + fn clone(&self) -> Self { + Self { + buffer: self.buffer.clone(), + } + } +} + impl fmt::Debug for LinearMap where N: ArrayLength<(K, V)>, @@ -434,6 +447,18 @@ where } } +impl<'a, K, V> Clone for Iter<'a, K, V> +where + K: 'a, + V: 'a, +{ + fn clone(&self) -> Self { + Self { + iter: self.iter.clone(), + } + } +} + pub struct IterMut<'a, K, V> where K: 'a, diff --git a/src/spsc/mod.rs b/src/spsc/mod.rs index f0fc37a9..00dfc12d 100644 --- a/src/spsc/mod.rs +++ b/src/spsc/mod.rs @@ -408,6 +408,22 @@ where len: usize, } +impl<'a, T, N, U, C> Clone for Iter<'a, T, N, U, C> +where + N: ArrayLength + 'a, + T: 'a, + U: 'a + sealed::Uxx, + C: 'a + sealed::XCore, +{ + fn clone(&self) -> Self { + Self { + rb: self.rb, + index: self.index, + len: self.len, + } + } +} + /// A mutable iterator over the items of a queue pub struct IterMut<'a, T, N, U, C> where diff --git a/src/string.rs b/src/string.rs index e681c17c..64e1a5f7 100644 --- a/src/string.rs +++ b/src/string.rs @@ -414,6 +414,17 @@ where } } +impl Clone for String +where + N: ArrayLength, +{ + fn clone(&self) -> Self { + Self { + vec: self.vec.clone(), + } + } +} + impl fmt::Debug for String where N: ArrayLength, @@ -549,6 +560,16 @@ mod tests { static mut _S: String = String::new(); } + #[test] + fn clone() { + let s1: String = String::from("abcd"); + let mut s2 = s1.clone(); + s2.push_str(" efgh").unwrap(); + + assert_eq!(s1, "abcd"); + assert_eq!(s2, "abcd efgh"); + } + #[test] fn debug() { extern crate std; diff --git a/src/vec.rs b/src/vec.rs index b067aeaf..b05c2fda 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -43,6 +43,18 @@ where len: usize, } +impl Clone for Vec +where + N: ArrayLength, + T: Clone, +{ + fn clone(&self) -> Self { + let mut new = Self::new(); + new.extend_from_slice(self.as_ref()).unwrap(); + new + } +} + impl Vec where N: ArrayLength, @@ -361,6 +373,19 @@ where } } +impl Clone for IntoIter +where + T: Clone, + N: ArrayLength, +{ + fn clone(&self) -> Self { + Self { + vec: self.vec.clone(), + next: self.next, + } + } +} + impl Drop for IntoIter where N: ArrayLength,