4 ms·
Children of a non-leaf tree node must be optional because otherwise the node would be forced to have both children. It's therefore obvious that Box means option
by HelloNurse 7y ago
Children of a non-leaf tree node must be optional because otherwise the node would be forced to have both children.
It's therefore obvious that Box means optional; otherwise there would be a bare Tree<A> to represent a mandatory reference.
- the_af 7y agoI don't know Rust (though I'm familiar with Java & C) and there's nothing obvious about Box. In fact, I'm just learning from your comment that it means optional.
- steveklabnik 7y ago(Box does not mean optional, the parent is wrong. Option is the type for optional. Box is basically a mallloc, placing a value in the newly allocated memory, and then a call to free automatically when it goes out of scope. The box itself is a pointer to the heap. It’s not allowed to be null, in some sense, the opposite of optional.)