Hi all. I feel like I'm missing something obvious here. I have two structs which depend on each other:
struct A {
b: Rc<RefCell<B>>,
}
struct B {
a: Weak<RefCell<A>>,
}
and a new function to construct them:
impl A {
pub fn new() -> Rc<RefCell<A>> {
let b = Rc::new(RefCell::new(B::new()));
let a = Rc::new(RefCell::new(A {b: b.clone()}));
// in B, fn set_a(&mut self, a: Weak<A>)
b.borrow_mut().set_a(Rc::downgrade(&a.clone()));
drop(b);
a
}
}
In the line where I call Rc::downgrade, the compiler complains that it's expected a reference to an Rc, but it's getting a reference to the contained RefCell. Why am I not getting a reference to the Rc itself?