#static #no-heap

no-std heapless

static friendly data structures that don’t require dynamic memory allocation

26 releases

✓ Uses Rust 2018 edition

0.5.3 Jan 27, 2020
0.5.1 Aug 29, 2019
0.5.0 Jul 11, 2019
0.4.2 Feb 12, 2019
0.1.0 Apr 27, 2017

#22 in Data structures

Download history 1144/week @ 2019-12-14 854/week @ 2019-12-21 1473/week @ 2019-12-28 994/week @ 2020-01-04 1932/week @ 2020-01-11 1618/week @ 2020-01-18 1667/week @ 2020-01-25 1889/week @ 2020-02-01 2123/week @ 2020-02-08 1628/week @ 2020-02-15 1948/week @ 2020-02-22 1368/week @ 2020-02-29 2764/week @ 2020-03-07 1866/week @ 2020-03-14 2029/week @ 2020-03-21 1708/week @ 2020-03-28

6,404 downloads per month
Used in 91 crates (44 directly)



crates.io crates.io


static friendly data structures that don't require dynamic memory allocation


Change log


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


static friendly data structures that don't require dynamic memory allocation

The core principle behind heapless is that its data structures are backed by a static memory allocation. For example, you can think of heapless::Vec as an alternative version of std::Vec with fixed capacity and that can't be re-allocated on the fly (e.g. via push).

All heapless data structures store their memory allocation inline and specify their capacity via their type parameter N. This means that you can instantiate a heapless data structure on the stack, in a static variable, or even in the heap.

use heapless::Vec; // fixed capacity `std::Vec`
use heapless::consts::U8; // type level integer used to specify capacity

// on the stack
let mut xs: Vec<u8, U8> = Vec::new(); // can hold up to 8 elements
assert_eq!(xs.pop(), Some(42));

// in a `static` variable
// (because `const-fn` has not been fully stabilized you need to use the helper structs in
// the `i` module, which must be wrapped in a tuple struct)
static mut XS: Vec<u8, U8> = Vec(heapless::i::Vec::new());

let xs = unsafe { &mut XS };

assert_eq!(xs.pop(), Some(42));

// in the heap (though kind of pointless because no reallocation)
let mut ys: Box<Vec<u8, U8>> = Box::new(Vec::new());
assert_eq!(ys.pop(), Some(42));

Because they have fixed capacity heapless data structures don't implicitly reallocate. This means that operations like heapless::Vec.push are truly constant time rather than amortized constant time with potentially unbounded (depends on the allocator) worst case execution time (which is bad / unacceptable for hard real time applications).

heapless data structures don't use a memory allocator which means no risk of an uncatchable Out Of Memory (OOM) condition while performing operations on them. It's certainly possible to run out of capacity while growing heapless data structures, but the API lets you handle this possibility by returning a Result on operations that may exhaust the capacity of the data structure.

List of currently implemented data structures:

Minimum Supported Rust Version (MSRV)

This crate is guaranteed to compile on stable Rust 1.36 and up with its default set of features. It might compile on older versions but that may change in any new patch release.