@@ -196,27 +196,27 @@ impl<N: Debug, E: Debug> Graph<N, E> {
196
196
197
197
// # Iterating over nodes, edges
198
198
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) )
203
204
}
204
205
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) )
209
211
}
210
212
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
213
214
{
214
215
//! Iterates over all edges defined in the graph.
215
216
self . enumerated_nodes ( ) . all ( |( node_idx, node) | f ( node_idx, node) )
216
217
}
217
218
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
220
220
{
221
221
//! Iterates over all edges defined in the graph
222
222
self . enumerated_edges ( ) . all ( |( edge_idx, edge) | f ( edge_idx, edge) )
@@ -239,11 +239,17 @@ impl<N: Debug, E: Debug> Graph<N, E> {
239
239
}
240
240
}
241
241
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 {
243
246
self . outgoing_edges ( source) . targets ( )
244
247
}
245
248
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 {
247
253
self . incoming_edges ( target) . sources ( )
248
254
}
249
255
@@ -293,34 +299,6 @@ impl<N: Debug, E: Debug> Graph<N, E> {
293
299
294
300
// # Iterators
295
301
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
-
324
302
pub struct AdjacentEdges < ' g , N , E >
325
303
where N : ' g ,
326
304
E : ' g
@@ -330,13 +308,13 @@ pub struct AdjacentEdges<'g, N, E>
330
308
next : EdgeIndex ,
331
309
}
332
310
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 )
336
314
}
337
315
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 )
340
318
}
341
319
}
342
320
@@ -355,36 +333,6 @@ impl<'g, N: Debug, E: Debug> Iterator for AdjacentEdges<'g, N, E> {
355
333
}
356
334
}
357
335
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
-
388
336
pub struct DepthFirstTraversal < ' g , N , E >
389
337
where N : ' g ,
390
338
E : ' g
0 commit comments