I'm trying to write a renderer for my abstract node system.
Each node is on a circuit, which looks like:
struct Circuit<'a> {
nodes: Vec<Node>,
connections: Vec<Connection<'a>>,
}
Where each nodes contains some arbitrary data, and a connection connects those two nodes.
struct Connection<'a> {
from: &'a Node,
to: &'a Node,
}
In one instance, I'm trying to mutably iterate over Circuit.nodes
and change some data, while still keeping the refences to Node
inside Connections
. I want the Connection
references to still hold the reference to the same Node
structs, but point to the updated data after the mutable borrow.
But with this setup, I get an cannot borrow 'circuit.nodes' as mutable because it is also borrowed as immutable
error.
I have tried to use RefCell
and a Mutex
, but to no success. No resource I could find explained this problem well.