2

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?

mcarton
  • 27,633
  • 5
  • 85
  • 95
vuilehaid
  • 342
  • 2
  • 8

1 Answers1

2

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.

Chris Emerson
  • 13,041
  • 3
  • 44
  • 66