3 ms·
Box puts something on the heap and returns a pointer to that thing. Here it is necessary because otherwise the Rust compile wouldn't be able to determine the si
by Munksgaard 7y ago
Box puts something on the heap and returns a pointer to that thing. Here it is necessary because otherwise the Rust compile wouldn't be able to determine the size (in memory) of a Tree.
- SamReidHughes 7y agoBox<T> is a type, so it’s confusing to say it returns a pointer. It holds a pointer. GP should note that C++’s unique_ptr isn’t an obscurity.
- HorstG 7y agoCalling it Box is confusing. unique_ptr would be an improvement for the name, or maybe HeapRef. The problem is exactly that rust chose a misleading name Box (boxed types are something entirely different in most languages) instead of the obvious C(++)/Java-like _ptr, ref, * or & notation/convention
- nicoburns 7y agoBoxed types in Java are basically the same thing: a heap allocated version of an otherwise stack-allocated type.
- axelf4 7y ago> instead of the obvious C(++)/Java-like _ptr, ref, * or & notation/convention That would be very misleading since Box represents a heap-allocated owned value
- SamReidHughes 7y agoI thought the name was pretty clear; when I saw it in some list of different kinds of Rust pointers, I knew what it was immediately. It doesn't matter if some people are confused, because you can just explain what it is in 3 seconds. What's important for such a ubiquitous type is that the name is short.