Im building a data structure containing nodes, and each node might point to another. The pointers between the nodes are implemented using Rc, something like this:
struct Node {
ptr: Rc<Node>
}
I would like to be able to change the pointer 'ptr' of a node to point to another node, by cloning another existing Rc.
let a: Rc<Node> = ...;
let mut b: Node = ...;
let b.ptr = a.clone();
My problem is, the compiler think I am trying to set the value of the node, namely changing the underlying shared object of b.ptr, where I realy want to replace the pointer: reduce the refcount of the old value of b.ptr, increase the refcount of a, and change b.ptr to point to a.
I managed to do it with Cell<Rc>, but I seems too vebose and unnecessary.
How can I do that?