@@ -66,7 +66,7 @@ impl<K, V> Default for DependencyGraph<K, V> {
66
66
}
67
67
}
68
68
69
- impl < K : Ord + Clone , V : Clone > DependencyGraph < K , V > {
69
+ impl < K : Ord + Copy , V : Clone > DependencyGraph < K , V > {
70
70
/// Inserts a new node into the graph.
71
71
///
72
72
/// # Errors
@@ -82,19 +82,19 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
82
82
let missing_parents = parents
83
83
. iter ( )
84
84
. filter ( |parent| !self . vertices . contains_key ( parent) )
85
- . cloned ( )
85
+ . copied ( )
86
86
. collect :: < BTreeSet < _ > > ( ) ;
87
87
if !missing_parents. is_empty ( ) {
88
88
return Err ( GraphError :: MissingParents ( missing_parents) ) ;
89
89
}
90
90
91
91
// Inform parents of their new child.
92
92
for parent in & parents {
93
- self . children . entry ( parent. clone ( ) ) . or_default ( ) . insert ( key. clone ( ) ) ;
93
+ self . children . entry ( * parent) . or_default ( ) . insert ( key) ;
94
94
}
95
- self . vertices . insert ( key. clone ( ) , value) ;
96
- self . parents . insert ( key. clone ( ) , parents) ;
97
- self . children . insert ( key. clone ( ) , Default :: default ( ) ) ;
95
+ self . vertices . insert ( key, value) ;
96
+ self . parents . insert ( key, parents) ;
97
+ self . children . insert ( key, Default :: default ( ) ) ;
98
98
99
99
self . try_make_root ( key) ;
100
100
@@ -115,12 +115,12 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
115
115
let missing_nodes = keys
116
116
. iter ( )
117
117
. filter ( |key| !self . vertices . contains_key ( key) )
118
- . cloned ( )
118
+ . copied ( )
119
119
. collect :: < BTreeSet < _ > > ( ) ;
120
120
if !missing_nodes. is_empty ( ) {
121
121
return Err ( GraphError :: UnknownNodes ( missing_nodes) ) ;
122
122
}
123
- let unprocessed = keys. difference ( & self . processed ) . cloned ( ) . collect :: < BTreeSet < _ > > ( ) ;
123
+ let unprocessed = keys. difference ( & self . processed ) . copied ( ) . collect :: < BTreeSet < _ > > ( ) ;
124
124
if !unprocessed. is_empty ( ) {
125
125
return Err ( GraphError :: UnprocessedNodes ( unprocessed) ) ;
126
126
}
@@ -137,7 +137,7 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
137
137
. map ( |children| children. difference ( & reverted) )
138
138
. into_iter ( )
139
139
. flatten ( )
140
- . cloned ( ) ;
140
+ . copied ( ) ;
141
141
142
142
to_revert. extend ( unprocessed_children) ;
143
143
@@ -176,13 +176,13 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
176
176
let missing_nodes = keys
177
177
. iter ( )
178
178
. filter ( |key| !self . vertices . contains_key ( key) )
179
- . cloned ( )
179
+ . copied ( )
180
180
. collect :: < BTreeSet < _ > > ( ) ;
181
181
if !missing_nodes. is_empty ( ) {
182
182
return Err ( GraphError :: UnknownNodes ( missing_nodes) ) ;
183
183
}
184
184
185
- let unprocessed = keys. difference ( & self . processed ) . cloned ( ) . collect :: < BTreeSet < _ > > ( ) ;
185
+ let unprocessed = keys. difference ( & self . processed ) . copied ( ) . collect :: < BTreeSet < _ > > ( ) ;
186
186
if !unprocessed. is_empty ( ) {
187
187
return Err ( GraphError :: UnprocessedNodes ( unprocessed) ) ;
188
188
}
@@ -193,7 +193,7 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
193
193
. flat_map ( |key| self . parents . get ( key) )
194
194
. flatten ( )
195
195
. filter ( |parent| !keys. contains ( parent) )
196
- . cloned ( )
196
+ . copied ( )
197
197
. collect :: < BTreeSet < _ > > ( ) ;
198
198
if !dangling. is_empty ( ) {
199
199
return Err ( GraphError :: DanglingNodes ( dangling) ) ;
@@ -236,7 +236,7 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
236
236
let missing_nodes = keys
237
237
. iter ( )
238
238
. filter ( |key| !self . vertices . contains_key ( key) )
239
- . cloned ( )
239
+ . copied ( )
240
240
. collect :: < BTreeSet < _ > > ( ) ;
241
241
if !missing_nodes. is_empty ( ) {
242
242
return Err ( GraphError :: UnknownNodes ( missing_nodes) ) ;
@@ -251,15 +251,15 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
251
251
. vertices
252
252
. remove ( & key)
253
253
. expect ( "Node was checked in precondition and must therefore exist" ) ;
254
- removed. insert ( key. clone ( ) , value) ;
254
+ removed. insert ( key, value) ;
255
255
256
256
self . processed . remove ( & key) ;
257
257
self . roots . remove ( & key) ;
258
258
259
259
// Children must also be purged. Take care not to visit them twice which is
260
260
// possible since children can have multiple purged parents.
261
261
let unvisited_children = self . children . remove ( & key) . unwrap_or_default ( ) ;
262
- let unvisited_children = unvisited_children. difference ( & visited) . cloned ( ) ;
262
+ let unvisited_children = unvisited_children. difference ( & visited) ;
263
263
to_remove. extend ( unvisited_children) ;
264
264
265
265
// Inform parents that this child no longer exists.
@@ -315,7 +315,7 @@ impl<K: Ord + Clone, V: Clone> DependencyGraph<K, V> {
315
315
return Err ( GraphError :: NotARootNode ( key) ) ;
316
316
}
317
317
318
- self . processed . insert ( key. clone ( ) ) ;
318
+ self . processed . insert ( key) ;
319
319
320
320
self . children
321
321
. get ( & key)
@@ -374,7 +374,7 @@ mod tests {
374
374
375
375
/// Calls process_root until all nodes have been processed.
376
376
fn process_all ( & mut self ) {
377
- while let Some ( root) = self . roots ( ) . first ( ) . cloned ( ) {
377
+ while let Some ( root) = self . roots ( ) . first ( ) . copied ( ) {
378
378
/// SAFETY: this is definitely a root since we just took it from there :)
379
379
self . process_root ( root) ;
380
380
}
0 commit comments