graphrustdataflowpetgraph

Mutable access to two nodes in petgraph


I am using the petgraph crate to implement a dataflow graph. I would like to copy data from an edge source node to its target node. For that I would need a mutable reference to the target node and an immutable reference to the source node. However Rust's borrow checker prevents that from happening since both a mutable and immutable reference is taken to the graph at the same time.

Is there a function available in petgraph that provides mutable references to multiple nodes at the same time?


Solution

  • The index_twice_mut method is the way to do that.

    Note that it panics if you try to index the same object twice, so you need to check that first.