Generic_slab - slab on steroids

โš“ Rust    ๐Ÿ“… 2025-12-18    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 2      

surdeus

Hey folks,

Iโ€™d like to introduce my new crate generic_slab.

github
crates.io
docs.rs

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

Read full topic

๐Ÿท๏ธ Rust_feed