#stack #vec #no-std #vector #small

no-std smallvec

'Small vector' optimization: store up to a small number of items on the stack

53 releases (22 stable)

2.0.0-alpha.11 Mar 20, 2025
2.0.0-alpha.9 Dec 17, 2024
2.0.0-alpha.7 Jul 27, 2024
2.0.0-alpha.5 Mar 23, 2024
0.1.5 Jun 30, 2015

#8 in Data structures

Download history 3607333/week @ 2024-12-05 3371776/week @ 2024-12-12 2371663/week @ 2024-12-19 1588614/week @ 2024-12-26 2757351/week @ 2025-01-02 3318479/week @ 2025-01-09 3165165/week @ 2025-01-16 3389783/week @ 2025-01-23 3698874/week @ 2025-01-30 3798230/week @ 2025-02-06 3955741/week @ 2025-02-13 4544621/week @ 2025-02-20 4191441/week @ 2025-02-27 4476732/week @ 2025-03-06 4527670/week @ 2025-03-13 4433719/week @ 2025-03-20

18,370,079 downloads per month
Used in 55,942 crates (1,768 directly)

MIT/Apache

110KB
2.5K SLoC

rust-smallvec

⚠️ Note: This is the code for smallvec 2.0, which is not yet ready for release. For details about the changes in version 2.0, please see #183, #240, and #284.

The source code for the latest smallvec 1.x.y release can be found on the v1 branch. Bug fixes for smallvec 1 should be based on that branch, while new feature development should go on the v2 branch.

About smallvec

Documentation

Release notes

"Small vector" optimization for Rust: store up to a small number of items on the stack

Example

use smallvec::{SmallVec, smallvec};
    
// This SmallVec can hold up to 4 items on the stack:
let mut v: SmallVec<i32, 4> = smallvec![1, 2, 3, 4];

// It will automatically move its contents to the heap if
// contains more than four items:
v.push(5);

// SmallVec points to a slice, so you can use normal slice
// indexing and other methods to access its contents:
v[0] = v[1] + v[2];
v.sort();

Dependencies

~215KB