summary refs log tree commit diff
path: root/src/librustc_data_structures/graph
diff options
context:
space:
mode:
authorCorey Farwell <coreyf@rwell.org>2018-03-03 10:22:07 -0500
committerCorey Farwell <coreyf@rwell.org>2018-03-07 20:09:32 -0500
commit3e60d996a00c6151b635994820edeb43ffd12e6c (patch)
treebbe9ad2092dd498ae2e43eb3467b084b840c3de9 /src/librustc_data_structures/graph
parent2789b067da2ac921b86199bde21dd231ace1da39 (diff)
downloadrust-3e60d996a00c6151b635994820edeb43ffd12e6c.tar.gz
rust-3e60d996a00c6151b635994820edeb43ffd12e6c.zip
Replace iterator structures with `impl Trait`.
Diffstat (limited to 'src/librustc_data_structures/graph')
-rw-r--r--src/librustc_data_structures/graph/mod.rs102
1 files changed, 25 insertions, 77 deletions
diff --git a/src/librustc_data_structures/graph/mod.rs b/src/librustc_data_structures/graph/mod.rs
index 56d5f5ffa3f..9ce9c738b16 100644
--- a/src/librustc_data_structures/graph/mod.rs
+++ b/src/librustc_data_structures/graph/mod.rs
@@ -196,27 +196,27 @@ impl<N: Debug, E: Debug> Graph<N, E> {
 
     // # Iterating over nodes, edges
 
-    pub fn enumerated_nodes(&self) -> EnumeratedNodes<N> {
-        EnumeratedNodes {
-            iter: self.nodes.iter().enumerate()
-        }
+    pub fn enumerated_nodes(&self) -> impl Iterator<Item = (NodeIndex, &Node<N>)> {
+        self.nodes
+            .iter()
+            .enumerate()
+            .map(|(idx, n)| (NodeIndex(idx), n))
     }
 
-    pub fn enumerated_edges(&self) -> EnumeratedEdges<E> {
-        EnumeratedEdges {
-            iter: self.edges.iter().enumerate()
-        }
+    pub fn enumerated_edges(&self) -> impl Iterator<Item = (EdgeIndex, &Edge<E>)> {
+        self.edges
+            .iter()
+            .enumerate()
+            .map(|(idx, e)| (EdgeIndex(idx), e))
     }
 
-    pub fn each_node<'a, F>(&'a self, mut f: F) -> bool
-        where F: FnMut(NodeIndex, &'a Node<N>) -> bool
+    pub fn each_node<'a>(&'a self, mut f: impl FnMut(NodeIndex, &'a Node<N>) -> bool) -> bool
     {
         //! Iterates over all edges defined in the graph.
         self.enumerated_nodes().all(|(node_idx, node)| f(node_idx, node))
     }
 
-    pub fn each_edge<'a, F>(&'a self, mut f: F) -> bool
-        where F: FnMut(EdgeIndex, &'a Edge<E>) -> bool
+    pub fn each_edge<'a>(&'a self, mut f: impl FnMut(EdgeIndex, &'a Edge<E>) -> bool) -> bool
     {
         //! Iterates over all edges defined in the graph
         self.enumerated_edges().all(|(edge_idx, edge)| f(edge_idx, edge))
@@ -239,11 +239,17 @@ impl<N: Debug, E: Debug> Graph<N, E> {
         }
     }
 
-    pub fn successor_nodes(&self, source: NodeIndex) -> AdjacentTargets<N, E> {
+    pub fn successor_nodes<'a>(
+        &'a self,
+        source: NodeIndex,
+    ) -> impl Iterator<Item = NodeIndex> + 'a {
         self.outgoing_edges(source).targets()
     }
 
-    pub fn predecessor_nodes(&self, target: NodeIndex) -> AdjacentSources<N, E> {
+    pub fn predecessor_nodes<'a>(
+        &'a self,
+        target: NodeIndex,
+    ) -> impl Iterator<Item = NodeIndex> + 'a {
         self.incoming_edges(target).sources()
     }
 
@@ -293,34 +299,6 @@ impl<N: Debug, E: Debug> Graph<N, E> {
 
 // # Iterators
 
-pub struct EnumeratedNodes<'g, N>
-    where N: 'g,
-{
-    iter: ::std::iter::Enumerate<::std::slice::Iter<'g, Node<N>>>
-}
-
-impl<'g, N: Debug> Iterator for EnumeratedNodes<'g, N> {
-    type Item = (NodeIndex, &'g Node<N>);
-
-    fn next(&mut self) -> Option<(NodeIndex, &'g Node<N>)> {
-        self.iter.next().map(|(idx, n)| (NodeIndex(idx), n))
-    }
-}
-
-pub struct EnumeratedEdges<'g, E>
-    where E: 'g,
-{
-    iter: ::std::iter::Enumerate<::std::slice::Iter<'g, Edge<E>>>
-}
-
-impl<'g, E: Debug> Iterator for EnumeratedEdges<'g, E> {
-    type Item = (EdgeIndex, &'g Edge<E>);
-
-    fn next(&mut self) -> Option<(EdgeIndex, &'g Edge<E>)> {
-        self.iter.next().map(|(idx, e)| (EdgeIndex(idx), e))
-    }
-}
-
 pub struct AdjacentEdges<'g, N, E>
     where N: 'g,
           E: 'g
@@ -330,13 +308,13 @@ pub struct AdjacentEdges<'g, N, E>
     next: EdgeIndex,
 }
 
-impl<'g, N, E> AdjacentEdges<'g, N, E> {
-    fn targets(self) -> AdjacentTargets<'g, N, E> {
-        AdjacentTargets { edges: self }
+impl<'g, N: Debug, E: Debug> AdjacentEdges<'g, N, E> {
+    fn targets(self) -> impl Iterator<Item = NodeIndex> + 'g {
+        self.into_iter().map(|(_, edge)| edge.target)
     }
 
-    fn sources(self) -> AdjacentSources<'g, N, E> {
-        AdjacentSources { edges: self }
+    fn sources(self) -> impl Iterator<Item = NodeIndex> + 'g {
+        self.into_iter().map(|(_, edge)| edge.source)
     }
 }
 
@@ -355,36 +333,6 @@ impl<'g, N: Debug, E: Debug> Iterator for AdjacentEdges<'g, N, E> {
     }
 }
 
-pub struct AdjacentTargets<'g, N, E>
-    where N: 'g,
-          E: 'g
-{
-    edges: AdjacentEdges<'g, N, E>,
-}
-
-impl<'g, N: Debug, E: Debug> Iterator for AdjacentTargets<'g, N, E> {
-    type Item = NodeIndex;
-
-    fn next(&mut self) -> Option<NodeIndex> {
-        self.edges.next().map(|(_, edge)| edge.target)
-    }
-}
-
-pub struct AdjacentSources<'g, N, E>
-    where N: 'g,
-          E: 'g
-{
-    edges: AdjacentEdges<'g, N, E>,
-}
-
-impl<'g, N: Debug, E: Debug> Iterator for AdjacentSources<'g, N, E> {
-    type Item = NodeIndex;
-
-    fn next(&mut self) -> Option<NodeIndex> {
-        self.edges.next().map(|(_, edge)| edge.source)
-    }
-}
-
 pub struct DepthFirstTraversal<'g, N, E>
     where N: 'g,
           E: 'g