@@ -241,7 +241,7 @@ fn dump_graph(query: &DepGraphQuery) {
241241 let targets = node_set ( & query, & edge_filter. target ) ;
242242 filter_nodes ( & query, & sources, & targets)
243243 }
244- Err ( _) => query. nodes ( ) . into_iter ( ) . collect ( ) ,
244+ Err ( _) => query. nodes ( ) . into_iter ( ) . map ( |n| n . kind ) . collect ( ) ,
245245 } ;
246246 let edges = filter_edges ( & query, & nodes) ;
247247
@@ -264,41 +264,41 @@ fn dump_graph(query: &DepGraphQuery) {
264264}
265265
266266#[ allow( missing_docs) ]
267- pub struct GraphvizDepGraph < ' q > ( FxHashSet < & ' q DepNode > , Vec < ( & ' q DepNode , & ' q DepNode ) > ) ;
267+ pub struct GraphvizDepGraph ( FxHashSet < DepKind > , Vec < ( DepKind , DepKind ) > ) ;
268268
269- impl < ' a , ' q > dot:: GraphWalk < ' a > for GraphvizDepGraph < ' q > {
270- type Node = & ' q DepNode ;
271- type Edge = ( & ' q DepNode , & ' q DepNode ) ;
272- fn nodes ( & self ) -> dot:: Nodes < ' _ , & ' q DepNode > {
269+ impl < ' a > dot:: GraphWalk < ' a > for GraphvizDepGraph {
270+ type Node = DepKind ;
271+ type Edge = ( DepKind , DepKind ) ;
272+ fn nodes ( & self ) -> dot:: Nodes < ' _ , DepKind > {
273273 let nodes: Vec < _ > = self . 0 . iter ( ) . cloned ( ) . collect ( ) ;
274274 nodes. into ( )
275275 }
276- fn edges ( & self ) -> dot:: Edges < ' _ , ( & ' q DepNode , & ' q DepNode ) > {
276+ fn edges ( & self ) -> dot:: Edges < ' _ , ( DepKind , DepKind ) > {
277277 self . 1 [ ..] . into ( )
278278 }
279- fn source ( & self , edge : & ( & ' q DepNode , & ' q DepNode ) ) -> & ' q DepNode {
279+ fn source ( & self , edge : & ( DepKind , DepKind ) ) -> DepKind {
280280 edge. 0
281281 }
282- fn target ( & self , edge : & ( & ' q DepNode , & ' q DepNode ) ) -> & ' q DepNode {
282+ fn target ( & self , edge : & ( DepKind , DepKind ) ) -> DepKind {
283283 edge. 1
284284 }
285285}
286286
287- impl < ' a , ' q > dot:: Labeller < ' a > for GraphvizDepGraph < ' q > {
288- type Node = & ' q DepNode ;
289- type Edge = ( & ' q DepNode , & ' q DepNode ) ;
287+ impl < ' a > dot:: Labeller < ' a > for GraphvizDepGraph {
288+ type Node = DepKind ;
289+ type Edge = ( DepKind , DepKind ) ;
290290 fn graph_id ( & self ) -> dot:: Id < ' _ > {
291291 dot:: Id :: new ( "DependencyGraph" ) . unwrap ( )
292292 }
293- fn node_id ( & self , n : & & ' q DepNode ) -> dot:: Id < ' _ > {
293+ fn node_id ( & self , n : & DepKind ) -> dot:: Id < ' _ > {
294294 let s: String = format ! ( "{:?}" , n)
295295 . chars ( )
296296 . map ( |c| if c == '_' || c. is_alphanumeric ( ) { c } else { '_' } )
297297 . collect ( ) ;
298298 debug ! ( "n={:?} s={:?}" , n, s) ;
299299 dot:: Id :: new ( s) . unwrap ( )
300300 }
301- fn node_label ( & self , n : & & ' q DepNode ) -> dot:: LabelText < ' _ > {
301+ fn node_label ( & self , n : & DepKind ) -> dot:: LabelText < ' _ > {
302302 dot:: LabelText :: label ( format ! ( "{:?}" , n) )
303303 }
304304}
@@ -323,7 +323,7 @@ fn filter_nodes<'q>(
323323 query : & ' q DepGraphQuery ,
324324 sources : & Option < FxHashSet < & ' q DepNode > > ,
325325 targets : & Option < FxHashSet < & ' q DepNode > > ,
326- ) -> FxHashSet < & ' q DepNode > {
326+ ) -> FxHashSet < DepKind > {
327327 if let Some ( sources) = sources {
328328 if let Some ( targets) = targets {
329329 walk_between ( query, sources, targets)
@@ -333,25 +333,25 @@ fn filter_nodes<'q>(
333333 } else if let Some ( targets) = targets {
334334 walk_nodes ( query, targets, INCOMING )
335335 } else {
336- query. nodes ( ) . into_iter ( ) . collect ( )
336+ query. nodes ( ) . into_iter ( ) . map ( |n| n . kind ) . collect ( )
337337 }
338338}
339339
340340fn walk_nodes < ' q > (
341341 query : & ' q DepGraphQuery ,
342342 starts : & FxHashSet < & ' q DepNode > ,
343343 direction : Direction ,
344- ) -> FxHashSet < & ' q DepNode > {
344+ ) -> FxHashSet < DepKind > {
345345 let mut set = FxHashSet :: default ( ) ;
346346 for & start in starts {
347347 debug ! ( "walk_nodes: start={:?} outgoing?={:?}" , start, direction == OUTGOING ) ;
348- if set. insert ( start) {
348+ if set. insert ( start. kind ) {
349349 let mut stack = vec ! [ query. indices[ start] ] ;
350350 while let Some ( index) = stack. pop ( ) {
351351 for ( _, edge) in query. graph . adjacent_edges ( index, direction) {
352352 let neighbor_index = edge. source_or_target ( direction) ;
353353 let neighbor = query. graph . node_data ( neighbor_index) ;
354- if set. insert ( neighbor) {
354+ if set. insert ( neighbor. kind ) {
355355 stack. push ( neighbor_index) ;
356356 }
357357 }
@@ -365,7 +365,7 @@ fn walk_between<'q>(
365365 query : & ' q DepGraphQuery ,
366366 sources : & FxHashSet < & ' q DepNode > ,
367367 targets : & FxHashSet < & ' q DepNode > ,
368- ) -> FxHashSet < & ' q DepNode > {
368+ ) -> FxHashSet < DepKind > {
369369 // This is a bit tricky. We want to include a node only if it is:
370370 // (a) reachable from a source and (b) will reach a target. And we
371371 // have to be careful about cycles etc. Luckily efficiency is not
@@ -396,6 +396,7 @@ fn walk_between<'q>(
396396 let index = query. indices [ n] ;
397397 node_states[ index. 0 ] == State :: Included
398398 } )
399+ . map ( |n| n. kind )
399400 . collect ( ) ;
400401
401402 fn recurse ( query : & DepGraphQuery , node_states : & mut [ State ] , node : NodeIndex ) -> bool {
@@ -433,11 +434,13 @@ fn walk_between<'q>(
433434
434435fn filter_edges < ' q > (
435436 query : & ' q DepGraphQuery ,
436- nodes : & FxHashSet < & ' q DepNode > ,
437- ) -> Vec < ( & ' q DepNode , & ' q DepNode ) > {
438- query
437+ nodes : & FxHashSet < DepKind > ,
438+ ) -> Vec < ( DepKind , DepKind ) > {
439+ let uniq : FxHashSet < _ > = query
439440 . edges ( )
440441 . into_iter ( )
441- . filter ( |& ( source, target) | nodes. contains ( source) && nodes. contains ( target) )
442- . collect ( )
442+ . map ( |( s, t) | ( s. kind , t. kind ) )
443+ . filter ( |( source, target) | nodes. contains ( source) && nodes. contains ( target) )
444+ . collect ( ) ;
445+ uniq. into_iter ( ) . collect ( )
443446}
0 commit comments