3 ms·
Rust's `Vec` already allocate values on the heap, so there is no need for another inderection with `Box`. this works: enum TreeNode<T> { Leaf(T),
by lame-lexem 2y ago
Rust's `Vec` already allocate values on the heap, so there is no need for another inderection with `Box`.
this works:
enum TreeNode<T> {
Leaf(T),
Branch(Vec<TreeNode<T>>),
}
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=4a116692a383e08d4dbe2e343529fa80 https://play.rust-lang.org/?version=stable&mode=debug&editio...
otherwise if it was just tuple of `TreeNode` there would be E0072 https://doc.rust-lang.org/stable/error_codes/E0072.html https://doc.rust-lang.org/stable/error_codes/E0072.html
- nicce 2y agoBox takes less space in stack, and you can use Box to move pointer to Vec contents easier, without mem::take. So if you want to min-max things, you could still use Box.