Why Box is named Box?


#1

I was reading chapter 15 of the book talking about smart pointers, and one of them is called Box<T>, which is a container and can store at most 1 element in heap.

To be honest, I could not figure out what does it do at first glance, by contrast, some types like HashSet, BTreeSet and LinkedList could be easily understood since they are common technical terms in CS. And because these types are all inside std::collections module, even though some people may not be familiar with these terms, they can still figure out that they are some kinds of containers which can store multiple elements.

So why Box is named Box?

Is it also a technical term in CS or it is only introduced in Rust?


#2

Putting a value on the heap and refering to it via a pointer is called boxing see:


#3

No, it actually contains exactly one element. A Box isn’t allowed to be empty. You need an Option<Box<T>> if you want one that can be empty.