Hacker News new | ask | show | jobs
by lame-lexem 654 days 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&editio...

otherwise if it was just tuple of `TreeNode` there would be E0072 https://doc.rust-lang.org/stable/error_codes/E0072.html

1 comments

Box 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.