News for hackers. Stuff that matters.
Re:Some notes on Rust by anon4 on Monday February 02, 2015 @03:43AM (#8983263)
Any reason you would ever want to return a Box instead of just a Foo, which the caller can then put in a Box if so desired?
Re:Some notes on Rust by kibwen on Monday February 02, 2015 @04:12AM (#8983345)
I can think of a case: when you want to return a type whose size is not known at runtime (a "dynamically-sized type" a.k.a. DST), then you need to stuff it behind something else whose size is known so that the compiler can statically determine how much memory to allocate before calling your function. You could use a reference for this task, but only if, as per Rust's usual rules, you have a parameter to your function whose lifetime you can tie it to. If you don't have such a parameter, then a Box is your next best bet.

Somewhat related to this, there's also currently a language deficiency where you can be forced to use Box when returning a closure from a function. This will be addressed shortly after 1.0.