MatrixGraph: implement Index/IndexMut for edges
diff --git a/src/matrix_graph.rs b/src/matrix_graph.rs
index f20692e..a4f6eaf 100644
--- a/src/matrix_graph.rs
+++ b/src/matrix_graph.rs
@@ -871,6 +871,30 @@
}
}
+/// Index the `MatrixGraph` by `NodeIndex` pair to access edge weights.
+///
+/// Also available with indexing syntax: `&graph[e]`.
+///
+/// **Panics** if no edge exists between `a` and `b`.
+impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> Index<(NodeIndex, NodeIndex)> for MatrixGraph<N, E, Ty, Null> {
+ type Output = E;
+
+ fn index(&self, (ax, bx): (NodeIndex, NodeIndex)) -> &E {
+ self.edge_weight(ax, bx)
+ }
+}
+
+/// Index the `MatrixGraph` by `NodeIndex` pair to access edge weights.
+///
+/// Also available with indexing syntax: `&mut graph[e]`.
+///
+/// **Panics** if no edge exists between `a` and `b`.
+impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> IndexMut<(NodeIndex, NodeIndex)> for MatrixGraph<N, E, Ty, Null> {
+ fn index_mut(&mut self, (ax, bx): (NodeIndex, NodeIndex)) -> &mut E {
+ self.edge_weight_mut(ax, bx)
+ }
+}
+
impl<N, E, Ty: EdgeType, Null: Nullable<Wrapped=E>> GetAdjacencyMatrix for MatrixGraph<N, E, Ty, Null> {
type AdjMatrix = ();