#vec #array #vector #stack #no_std

nightly no-std staticvec

Implements a fixed-capacity stack-allocated Vec alternative backed by an array, using const generics

60 releases (8 breaking)

new 0.10.2 Aug 1, 2020
0.10.1 Jun 27, 2020
0.9.3 May 31, 2020
0.9.2 Mar 18, 2020
0.1.6 Jul 31, 2019

#18 in Data structures

Download history 411/week @ 2020-04-13 56/week @ 2020-04-20 450/week @ 2020-04-27 838/week @ 2020-05-04 1050/week @ 2020-05-11 1226/week @ 2020-05-18 1421/week @ 2020-05-25 1517/week @ 2020-06-01 1313/week @ 2020-06-08 973/week @ 2020-06-15 1496/week @ 2020-06-22 1478/week @ 2020-06-29 903/week @ 2020-07-06 1482/week @ 2020-07-13 1291/week @ 2020-07-20 983/week @ 2020-07-27

5,316 downloads per month
Used in 12 crates (4 directly)


4.5K SLoC

Latest Version Rustc Version nightly

Build Status Build status

Implements a fixed-capacity stack-allocated Vec alternative backed by an array, using const generics.

Note: the word "static" here is meant by the traditional definition of "unchanging" / "not dynamic" etc.

This crate does not use literal static variables for anything (but does provide multiple ways to instantiate a StaticVec as a static or const variable if desired).

Fully #![no_std] compatible (with almost no loss of functionality) by setting default-features = false for the staticvec dependency in your Cargo.toml.

Optional support for serialization and deserialization of the StaticVec struct via serde is available by activating the serde_support crate feature.

StaticVec also implements both Deref and DerefMut to [T], meaning that all existing slice methods are accessible through instances of it and that references to it can be used in contexts where [T] is expected.

As of version 0.8.0, this crate additionally provides a fixed-capacity StaticString struct, which is built around an instance of StaticVec<u8, N>.

As of version 0.8.5, a fixed-capacity StaticHeap struct based on the standard library BinaryHeap and built around an instance of StaticVec<T, N> has been added as well.

Contributions/suggestions/etc. very welcome!

Minimum supported Rust version: due to the use of const generics, this is a nightly-only crate at the moment.

Important note regarding version 0.10.0 of this crate:

It exists solely because of the fact that the following list of functions:

  • concat
  • concat_clone
  • intersperse
  • intersperse_clone
  • symmetric_difference
  • union

were broken in a way by rust-lang PR #70107 that simply cannot be worked around at this time. If you rely on any of those functions, please continue using version 0.9.3 with a released-prior-to-June-3-2020 copy of the nightly compiler. Again, 0.9.3 would still be the latest version of this crate if it were the case that it were actually possible to do anything to fix the compilation error, but unfortunately that just is not the case right now.

A basic usage example:

use staticvec::{staticvec, StaticVec};

fn main() {
  let mut v = StaticVec::<usize, 64>::new();
  for i in 0..v.capacity() {
  for i in &v {
    println!("{}", i);
  v.insert(0, 47);
  v.insert(1, 48);
  v.insert(2, 49);
  v.insert(v.len() - 1, 50);
  v.insert(v.len() - 2, 51);
  v.insert(v.len() - 3, 52);
  for i in &v {
    println!("{}", i);
  for i in &v.reversed().drain(2..4) {
    println!("{}", i);
  while v.is_not_empty() {
    println!("{}", v.remove(0));
  for f in staticvec![12.0, 14.0, 15.0, 16.0].iter().skip(2) {
    println!("{}", f);
  for i in staticvec![
    staticvec![14, 12, 10].sorted(),
    staticvec![20, 18, 16].reversed(),
    staticvec![26, 24, 22].sorted(),
    staticvec![32, 30, 28].reversed(),
  .collect::<StaticVec<usize, 12>>()
  .iter() {
    println!("{}", i);


Licensed under either the MIT license or version 2.0 of the Apache License. Your choice as to which! Any source code contributions will be dual-licensed in the same fashion.