Hacker News new | ask | show | jobs
by steveklabnik 2426 days ago
You don't have to box, but you do need some sort of type to make things sized. This is usually a pointer of some kind, but any kind of pointer works. Take references, for example:

  enum List<'a, T> {
    Nil,
    Cons(T, &'a List<'a, T>)
  }
  
  fn main() {
      let list = List::Cons("hello", &List::Nil);
  }
Box is usually chosen because it's a good default choice.
1 comments

you're right of course! i should've used a more generic term like "indirection" or "reference", didn't mean to put emphasis on Box
It’s all good, most people say just Box, because it is the majority case.