We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 01bb540 commit 4f47f49Copy full SHA for 4f47f49
src/lib.rs
@@ -107,13 +107,33 @@ impl HashValue {
107
}
108
109
110
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Debug)]
111
struct Bucket<K, V> {
112
hash: HashValue,
113
key: K,
114
value: V,
115
116
117
+impl<K, V> Clone for Bucket<K, V>
118
+where
119
+ K: Clone,
120
+ V: Clone,
121
+{
122
+ fn clone(&self) -> Self {
123
+ Bucket {
124
+ hash: self.hash,
125
+ key: self.key.clone(),
126
+ value: self.value.clone(),
127
+ }
128
129
+
130
+ fn clone_from(&mut self, other: &Self) {
131
+ self.hash = other.hash;
132
+ self.key.clone_from(&other.key);
133
+ self.value.clone_from(&other.value);
134
135
+}
136
137
impl<K, V> Bucket<K, V> {
138
// field accessors -- used for `f` instead of closures in `.map(f)`
139
fn key_ref(&self) -> &K {
src/map.rs
@@ -77,19 +77,36 @@ fn hash_elem_using<B: BuildHasher, K: ?Sized + Hash>(build: &B, k: &K) -> HashVa
77
/// assert_eq!(letters[&'u'], 1);
78
/// assert_eq!(letters.get(&'y'), None);
79
/// ```
80
-#[derive(Clone)]
81
#[cfg(has_std)]
82
pub struct IndexMap<K, V, S = RandomState> {
83
core: IndexMapCore<K, V>,
84
hash_builder: S,
85
86
87
#[cfg(not(has_std))]
88
pub struct IndexMap<K, V, S> {
89
90
91
92
+impl<K, V, S> Clone for IndexMap<K, V, S>
93
94
95
+ S: Clone,
96
97
98
+ IndexMap {
99
+ core: self.core.clone(),
100
+ hash_builder: self.hash_builder.clone(),
101
102
103
104
105
+ self.core.clone_from(&other.core);
106
+ self.hash_builder.clone_from(&other.hash_builder);
impl<K, V, S> Entries for IndexMap<K, V, S> {
type Entry = Bucket<K, V>;
src/map_core.rs
@@ -362,7 +362,6 @@ where
362
363
364
/// Core of the map that does not depend on S
365
366
pub(crate) struct IndexMapCore<K, V> {
367
mask: usize,
368
/// indices are the buckets. indices.len() == raw capacity
@@ -371,6 +370,26 @@ pub(crate) struct IndexMapCore<K, V> {
371
370
entries: Vec<Bucket<K, V>>,
372
373
+impl<K, V> Clone for IndexMapCore<K, V>
374
375
376
377
378
379
+ IndexMapCore {
380
+ mask: self.mask,
381
+ indices: self.indices.clone(),
382
+ entries: self.entries.clone(),
383
384
385
386
387
+ self.mask = other.mask;
388
+ self.indices.clone_from(&other.indices);
389
+ self.entries.clone_from(&other.entries);
390
391
392
393
impl<K, V> Entries for IndexMapCore<K, V> {
394
395
src/set.rs
@@ -63,17 +63,31 @@ type Bucket<T> = super::Bucket<T, ()>;
63
/// assert!(letters.contains(&'u'));
64
/// assert!(!letters.contains(&'y'));
65
66
67
68
pub struct IndexSet<T, S = RandomState> {
69
map: IndexMap<T, (), S>,
70
71
72
73
pub struct IndexSet<T, S> {
74
75
76
+impl<T, S> Clone for IndexSet<T, S>
+ T: Clone,
+ IndexSet {
+ map: self.map.clone(),
+ self.map.clone_from(&other.map);
impl<T, S> Entries for IndexSet<T, S> {
type Entry = Bucket<T>;
0 commit comments