Holistic explanation of Cell and reference-counted types in Rust
I'm new to Rust and trying to understand how Cell, RefCell, Rc, and Arc work. They are described in the official documentation, but I'm missing the big picture — how these types relate to each other and when to use which.
Here's a specific example that confused me. I'm trying to create a graph where nodes can reference each other. I have a Node struct:
```rust
struct Node {
value: i32,
children: Vec,
}
```
But I can't add cyclic references because ownership requires each node to have a single owner. I tried using references with lifetimes:
```rust
struct Node<'a> {
value: i32,
children: Vec<&'a Node<'a>>,
}
```
But the compiler complains about lifetimes and I don't understand how to fix it. Then I read about Rc, but when I
No answers yet.
Log in to leave an answer