File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -830,6 +830,39 @@ impl<T> Graph<T> {
830830 VertexIter ( Box :: new ( neighbors) )
831831 }
832832
833+ /// Returns an iterator over all edges that are situated
834+ /// in the graph.
835+ ///
836+ /// ## Example
837+ /// ```rust
838+ /// use graphlib::Graph;
839+ ///
840+ /// let mut graph: Graph<usize> = Graph::new();
841+ /// let mut edges = vec![];
842+ ///
843+ /// let v1 = graph.add_vertex(0);
844+ /// let v2 = graph.add_vertex(1);
845+ /// let v3 = graph.add_vertex(2);
846+ /// let v4 = graph.add_vertex(3);
847+ ///
848+ /// graph.add_edge(&v1, &v2).unwrap();
849+ /// graph.add_edge(&v3, &v1).unwrap();
850+ /// graph.add_edge(&v1, &v4).unwrap();
851+ ///
852+ /// // Iterate over edges
853+ /// for v in graph.edges() {
854+ /// edges.push(v);
855+ /// }
856+ ///
857+ /// assert_eq!(edges.len(), 3);
858+ /// ```
859+ pub fn edges ( & self ) -> impl Iterator < Item = ( & VertexId , & VertexId ) > {
860+ self
861+ . edges
862+ . iter ( )
863+ . map ( |( e, _) | ( e. inbound ( ) , e. outbound ( ) ) )
864+ }
865+
833866 /// Returns an iterator over the root vertices
834867 /// of the graph.
835868 ///
You can’t perform that action at this time.
0 commit comments