#collection #array #stack

nightly no-std stack-array

A very fast maximally-sized array stored on the stack

39 releases (16 stable)

Uses new Rust 2024

new 1.2.9 Aug 19, 2026
1.1.3 Jul 30, 2026
0.11.0 Jul 22, 2026
0.4.1 Apr 10, 2022
0.2.4 Jan 25, 2022

#2813 in Data structures

Download history 2/week @ 2026-07-02 35/week @ 2026-07-09 14/week @ 2026-07-16 4/week @ 2026-07-23 17/week @ 2026-07-30 37/week @ 2026-08-06

76 downloads per month
Used in 2 crates

MIT license

42KB
1K SLoC

Array

Array<Type, N> is an stack-allocated vector of maximum capacity N, but not restricted to having an exact amount of elements as [Type; N].

Usage

use stack_array::Array;

let mut array = Array::<u8, 5>::new();

array.push(0);
array.push(3);

array.extend([1, 2]);

The Array type exposes an API similar to that of Vec with common functions:

  • .push(Type) -> (),
  • .pop() -> Option<Type>,
  • .extend(IntoIterator<Item = Type>) -> (),
  • .clear() -> (),
  • .insert(usize, Type) -> (),
  • .remove(usize) -> Type,
  • .swap_remove(usize) -> Type,
  • .retain(impl FnMut(&mut Type) -> bool) -> (),
  • .dedup() -> (),
  • .dedup_with(impl FnMut(&mut Type, &mut Type) -> bool) -> (),
  • .dedup_by_key<K: PartialEq>(impl FnMut(&mut Type) -> K) -> (),
  • .drain(impl RangeBounds<usize>) -> Self

The type implements Deref<Target = [Type]> along with DerefMut to access the methods of the slice type. There are also specialized functions for resizing the array.

Furthermore, most of its methods and implementations use cutting-edge nightly const-features, which allows for complex compile-time constants:

#![allow(incomplete_features)]

#![feature(generic_const_exprs)]
#![feature(const_convert)]
#![feature(const_trait_impl)]

use stack_array::Array;

static ARRAY: Array<u8, 6> = const {
    let mut instance = Array::<u8, 6>::from([1, 2, 3]);
    instance.push(4);
    instance.insert(0, 0);
    instance.pop().unwrap();
    instance
};

Performance

Array is stack-allocated, which means it does not make use of any allocator and maintains items inlined on the runtime stack or in the program memory.

Array Vec ArrayVec SmallVec
pushpop 845M/s 818M/s 826M/s 244M/s

Iterations per second, measured with rustc 1.100.0-nightly (e71c0f1e3 2026-08-18) on a MacBook M4.

When to use this type

This type should be used when you need to store a finite and reasonable number of elements in a list, and you care about performance.

Dependencies