How to create a cyclic reference with Arc and Weak?
问题 I have two structs: struct A { map: HashMap<u32, Vec<B>>, } struct B { weak: Weak<A> } When A is constructed, it will own several B , each of which links back to the A which was just constructed, similar to this: let a = Arc::new(A { map: HashMap::new() }); let b1 = B { weak: Arc::downgrade(&a) }; let b3 = B { weak: Arc::downgrade(&a) }; let b2 = B { weak: Arc::downgrade(&a) }; a.map.insert(5, vec![b1, b2]); a.map.insert(10, vec![b3]); Playground This doesn't work since Arc does not provide a