Merge pull request #275 from ultrasaurus/node_indices-doc
inline doc example for node_indices
diff --git a/src/graph_impl/mod.rs b/src/graph_impl/mod.rs
index dc8371d..91eea58 100644
--- a/src/graph_impl/mod.rs
+++ b/src/graph_impl/mod.rs
@@ -938,7 +938,18 @@
Externals{iter: self.nodes.iter().enumerate(), dir: dir, ty: PhantomData}
}
- /// Return an iterator over the node indices of the graph
+ /// Return an iterator over the node indices of the graph.
+ ///
+ /// For example, in a rare case where a graph algorithm were not applicable,
+ /// the following code will iterate through all nodes to find a
+ /// specific index:
+ ///
+ /// ```
+ /// # use petgraph::Graph;
+ /// # let mut g = Graph::<&str, i32>::new();
+ /// # g.add_node("book");
+ /// let index = g.node_indices().find(|i| g[*i] == "book").unwrap();
+ /// ```
pub fn node_indices(&self) -> NodeIndices<Ix> {
NodeIndices { r: 0..self.node_count(), ty: PhantomData }
}