<p dir="auto"><a href="https://github.com/servo/servo/blob/master/src/components/util/smallvec.rs">SmallVec</a> is a cool collection (family) that attempts to keep some small constant-sized number of elements in-stack before failing over to heap-allocated Slices.</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/aturon/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/aturon">@aturon</a> has indicated interest in including this, in some form, in libcollections.</p>
<p dir="auto">It's often useful to have a vector optimized for storing small sequences. LLVM includes a <code class="notranslate">SmallVector</code> templated type which takes the size to store inside the struct as a template parameter, which isn't possible at the moment in Rust. However, it would be fine to just copy what libc++ does for <code class="notranslate">std::string</code> which is to store 3 words in the struct (size, capacity, and the pointer) and reuse that space for the small string optimization.</p>