E0506 cannot assign because it is borrowed

Hi,
I have this code

Which is this

struct A<'a> {
data: u32,
all: Vec<&'a A<'a>>
}

impl<'a> A<'a> {
fn new() -> A<'a> {
A { data: 0, all: Vec::new() }
}
}

fn main() {
let mut a = A::new();
let mut b = A::new();
//a.all.push(&b);
b.all.push(&a);
println!(" {}", b.all[0].data);
a.data = 2;
println!(" {}", b.all[0].data);
}

I need a, b mutable maybe I have to use Rc or Weak.

Thanks.

If data is the only thing you need to modify, you could wrap it in a Cell. For more complicated (non-Copy) types, use RefCell instead.

Thanks. I tested the code

Rust Playground works, technically speaking, but it's extremely limited.

See Baby Steps and r4cppp/README.md at master · nrc/r4cppp · GitHub for practical advice how to build graph data structures in Rust.

Thanks for the example for line 15.