$ show rust-embedded/heapless
This is a Rust library providing fixed-capacity, heap-free data structures for embedded and no_std environments. It offers a comprehensive set of collectionsβVec, String, BinaryHeap, Deque, HistoryBuf, IndexMap, IndexSet, LinearMap, SortedLinkedListβall parameterized by const generics for stack allocation. Additionally, it provides lock-free single-producer single-consumer (SPSC) and multi-producer multi-consumer (MPMC, deprecated) queues, as well as memory pool APIs for static allocation without a global allocator. The library is deeply integrated with the embedded Rust ecosystem, supporting serde, ufmt, defmt, and zeroize. Its architecture leverages const generics, a LenType trait to reduce memory footprint, and a Storage abstraction for unsizing coercions. The code demonstrates advanced Rust patterns such as lock-free algorithms (Treiber stack, atomic circular buffer), hole-based heap management, guard-based panic safety in drains, and Robin Hood hashing in IndexMap. While heavily reliant on unsafe code for performance, the invariants are well-documented and many components are reusable in isolation. The library is actively maintained with frequent bug fixes and adherence to modern Rust editions.
The LLM identified 4 files worth highlighting for reuse:
Implements a lock-free single-producer single-consumer queue using a circular buffer with atomic head/tail indices. The split() method produces Producer and Consumer halves that can be used in interrupt handlers and main code respectively. This module is nearly self-contained (only depends on core) and demonstrates a portable, high-performance queue pattern suitable for any no_std environment.
Provides a lock-free Treiber stack implementation used as the internal data structure for memory pools. It supports push, pop, and compare-and-swap operations using either native LLSC instructions (ARM) or portable-atomic fallback. The pattern is a reusable lock-free LIFO container that can be extracted for other pool or allocator designs.
Contains the Hole struct that manages a single 'hole' during heap sift-up/sift-down operations. This pattern ensures safe drop of the moved element and allows reordering without double moves. It is a classic example of the 'hole' technique for in-heap mutations and can be reused in any binary heap implementation.
Implements a sorted linked list with a FindMut pattern that returns a mutable reference to a found element. When dropped, it automatically reinserts the element in the correct sorted position, maintaining list invariants. This guard-based mutation pattern is reusable for any ordered collection where mutation requires reordering.