Module stable_vec

Module stable_vec 

Source
Expand description

A vector data structure that maintains stable indices for its elements.

§Why Not slab?

The slab crate provides a similar Slab data structure. However, its insertion order is not necessarily preserved when elements are removed. For example, after clearing the slab, the next element might not be inserted at index 0, but rather it reuses some other slot. This can lead to seemingly non-deterministic behavior when clearing and repopulating scenes, for example.

This StableVec implementation instead always pushes elements to the first available slot with the lowest index, ensuring that insertion order is preserved across removals and clear operations.

§Why Not stable_vec?

The stable_vec crate provides a similar StableVec data structure. However, it doesn’t actually reuse slots of removed elements, leading to unbounded memory growth if elements are frequently added and removed. This makes it unsuitable for general-purpose use for gameplay scenarios.

This StableVec implementation reuses slots of removed elements, using the IdPool type to track free indices.

Structs§

StableVec
A Vec<T>-like collection that maintains stable indices for its elements.
StableVecIntoIterator
An iterator over the elements of a StableVec.