@@ -196,27 +196,27 @@ impl<N: Debug, E: Debug> Graph<N, E> {
196196
197197 // # Iterating over nodes, edges
198198
199- pub fn enumerated_nodes ( & self ) -> EnumeratedNodes < N > {
200- EnumeratedNodes {
201- iter : self . nodes . iter ( ) . enumerate ( )
202- }
199+ pub fn enumerated_nodes ( & self ) -> impl Iterator < Item = ( NodeIndex , & Node < N > ) > {
200+ self . nodes
201+ . iter ( )
202+ . enumerate ( )
203+ . map ( |( idx, n) | ( NodeIndex ( idx) , n) )
203204 }
204205
205- pub fn enumerated_edges ( & self ) -> EnumeratedEdges < E > {
206- EnumeratedEdges {
207- iter : self . edges . iter ( ) . enumerate ( )
208- }
206+ pub fn enumerated_edges ( & self ) -> impl Iterator < Item = ( EdgeIndex , & Edge < E > ) > {
207+ self . edges
208+ . iter ( )
209+ . enumerate ( )
210+ . map ( |( idx, e) | ( EdgeIndex ( idx) , e) )
209211 }
210212
211- pub fn each_node < ' a , F > ( & ' a self , mut f : F ) -> bool
212- where F : FnMut ( NodeIndex , & ' a Node < N > ) -> bool
213+ pub fn each_node < ' a > ( & ' a self , mut f : impl FnMut ( NodeIndex , & ' a Node < N > ) -> bool ) -> bool
213214 {
214215 //! Iterates over all edges defined in the graph.
215216 self . enumerated_nodes ( ) . all ( |( node_idx, node) | f ( node_idx, node) )
216217 }
217218
218- pub fn each_edge < ' a , F > ( & ' a self , mut f : F ) -> bool
219- where F : FnMut ( EdgeIndex , & ' a Edge < E > ) -> bool
219+ pub fn each_edge < ' a > ( & ' a self , mut f : impl FnMut ( EdgeIndex , & ' a Edge < E > ) -> bool ) -> bool
220220 {
221221 //! Iterates over all edges defined in the graph
222222 self . enumerated_edges ( ) . all ( |( edge_idx, edge) | f ( edge_idx, edge) )
@@ -239,11 +239,17 @@ impl<N: Debug, E: Debug> Graph<N, E> {
239239 }
240240 }
241241
242- pub fn successor_nodes ( & self , source : NodeIndex ) -> AdjacentTargets < N , E > {
242+ pub fn successor_nodes < ' a > (
243+ & ' a self ,
244+ source : NodeIndex ,
245+ ) -> impl Iterator < Item = NodeIndex > + ' a {
243246 self . outgoing_edges ( source) . targets ( )
244247 }
245248
246- pub fn predecessor_nodes ( & self , target : NodeIndex ) -> AdjacentSources < N , E > {
249+ pub fn predecessor_nodes < ' a > (
250+ & ' a self ,
251+ target : NodeIndex ,
252+ ) -> impl Iterator < Item = NodeIndex > + ' a {
247253 self . incoming_edges ( target) . sources ( )
248254 }
249255
@@ -293,34 +299,6 @@ impl<N: Debug, E: Debug> Graph<N, E> {
293299
294300// # Iterators
295301
296- pub struct EnumeratedNodes < ' g , N >
297- where N : ' g ,
298- {
299- iter : :: std:: iter:: Enumerate < :: std:: slice:: Iter < ' g , Node < N > > >
300- }
301-
302- impl < ' g , N : Debug > Iterator for EnumeratedNodes < ' g , N > {
303- type Item = ( NodeIndex , & ' g Node < N > ) ;
304-
305- fn next ( & mut self ) -> Option < ( NodeIndex , & ' g Node < N > ) > {
306- self . iter . next ( ) . map ( |( idx, n) | ( NodeIndex ( idx) , n) )
307- }
308- }
309-
310- pub struct EnumeratedEdges < ' g , E >
311- where E : ' g ,
312- {
313- iter : :: std:: iter:: Enumerate < :: std:: slice:: Iter < ' g , Edge < E > > >
314- }
315-
316- impl < ' g , E : Debug > Iterator for EnumeratedEdges < ' g , E > {
317- type Item = ( EdgeIndex , & ' g Edge < E > ) ;
318-
319- fn next ( & mut self ) -> Option < ( EdgeIndex , & ' g Edge < E > ) > {
320- self . iter . next ( ) . map ( |( idx, e) | ( EdgeIndex ( idx) , e) )
321- }
322- }
323-
324302pub struct AdjacentEdges < ' g , N , E >
325303 where N : ' g ,
326304 E : ' g
@@ -330,13 +308,13 @@ pub struct AdjacentEdges<'g, N, E>
330308 next : EdgeIndex ,
331309}
332310
333- impl < ' g , N , E > AdjacentEdges < ' g , N , E > {
334- fn targets ( self ) -> AdjacentTargets < ' g , N , E > {
335- AdjacentTargets { edges : self }
311+ impl < ' g , N : Debug , E : Debug > AdjacentEdges < ' g , N , E > {
312+ fn targets ( self ) -> impl Iterator < Item = NodeIndex > + ' g {
313+ self . into_iter ( ) . map ( | ( _ , edge ) | edge . target )
336314 }
337315
338- fn sources ( self ) -> AdjacentSources < ' g , N , E > {
339- AdjacentSources { edges : self }
316+ fn sources ( self ) -> impl Iterator < Item = NodeIndex > + ' g {
317+ self . into_iter ( ) . map ( | ( _ , edge ) | edge . source )
340318 }
341319}
342320
@@ -355,36 +333,6 @@ impl<'g, N: Debug, E: Debug> Iterator for AdjacentEdges<'g, N, E> {
355333 }
356334}
357335
358- pub struct AdjacentTargets < ' g , N , E >
359- where N : ' g ,
360- E : ' g
361- {
362- edges : AdjacentEdges < ' g , N , E > ,
363- }
364-
365- impl < ' g , N : Debug , E : Debug > Iterator for AdjacentTargets < ' g , N , E > {
366- type Item = NodeIndex ;
367-
368- fn next ( & mut self ) -> Option < NodeIndex > {
369- self . edges . next ( ) . map ( |( _, edge) | edge. target )
370- }
371- }
372-
373- pub struct AdjacentSources < ' g , N , E >
374- where N : ' g ,
375- E : ' g
376- {
377- edges : AdjacentEdges < ' g , N , E > ,
378- }
379-
380- impl < ' g , N : Debug , E : Debug > Iterator for AdjacentSources < ' g , N , E > {
381- type Item = NodeIndex ;
382-
383- fn next ( & mut self ) -> Option < NodeIndex > {
384- self . edges . next ( ) . map ( |( _, edge) | edge. source )
385- }
386- }
387-
388336pub struct DepthFirstTraversal < ' g , N , E >
389337 where N : ' g ,
390338 E : ' g
0 commit comments