Rust containers and wrappers

A big part is that it helps to separate responsibilities in many cases.

In Vec, for example, the RawVec is responsible for allocating and freeing the (conceptual) array of MaybeUninit<T>s, while the Vec itself is responsible for keeping track of which of those elements are initialized, and dropping them at the right time.

See RawVec - The Rustonomicon for a long discussion about this.

4 Likes