Slide 5
Slide 5 text
Cell を使えば解決
struct Node<'a, T> {
pub value: T,
other: Cell>,
}
let node1 = Box::new(Node {
value: 123,
other: Cell::new(None), // None で初期化
});
let node2 = Box::new(Node {
value: 456,
other: Cell::new(None), // None で初期化
});
// ここで相互参照を作る
node1.other.set(Some(&node2));
node2.other.set(Some(&node1));
impl Cell {
pub fn set(&self, val: T) { … }
}
mut じゃないのでOK