4 ms·
Mostly to mimic the data structures allowed in languages where objects are held by reference. In Python, I could write a tree structure as `namedtuple(“node”,
by MereInterest 3y ago
Mostly to mimic the data structures allowed in languages where objects are held by reference. In Python, I could write a tree structure as `namedtuple(“node”, [“lhs”, “rhs”])`. If I tried to write a similar structure in Rust as `enum Node{Leaf, Branch(Node, Node)}`, the compiler rightfully complains that it would have an infinite size. But the indirection introduced by Box would let it be stored as `enum Node{Leaf, Branch(Box<Node>, Box<Node>)}`.
- jowea 3y agoI think what the previous poster is pointing out is that Box<Rc<Foo>> is an unnecessary double indirection.