Generic_slab - slab on steroids
โ Rust ๐ 2025-12-18 ๐ค surdeus ๐๏ธ 2Hey folks,
Iโd like to introduce my new crate generic_slab.
Most of us know and love the classic slab crate - itโs simple, fast, and great when you want to store lots of small objects behind usize keys. But when I needed something similar with custom key types, different backing storage, or no_std support, I kept running into its fixed design. So I built a fork that keeps the same feel, but opens everything up.
What is it?
generic_slab is a generalized version of slab with the same familiar Slab<T> type for compatibility, but also a fully customizable:
- GenericSlab<T, TKey, TEntries> (your own key + your own storage)
- StrongSlab (uses strongly typed Handle keys)
- Optional range iterators (feature = "range") for efficient key-range traversal
Basically: if you ever wanted slab-like performance without being stuck to usize keys or Vec storage, this crate is for you.
Why bother?
The original slab has two things baked in:
- the key type (
usize) - the storage backend (
Vec<Entry<_, _>>)
If that fits your needs, awesome - and generic_slab::Slab<T> works exactly the same. But if you want more flexibility, you now have it.
What can you customize?
Custom key types
Implement Key<T> for your own type, or use the built-in strongly typed Handle<T>.
No more accidentally mixing keys across slabs or types.
Custom storage
Implement Entries<T, K> for whatever backing store you want:
- ArrayVec
- fixed arrays (embedded)
- anything you control
Let me know what you think - happy to improve it based on your input!
1 post - 1 participant
๐ท๏ธ Rust_feed