| Crates.io | wrapped_slab |
| lib.rs | wrapped_slab |
| version | 0.4.0 |
| created_at | 2023-07-19 12:34:49.711401+00 |
| updated_at | 2025-04-17 10:25:55.514408+00 |
| description | WrappedSlab: Auto-generate newtype idiom based on a Slab |
| homepage | |
| repository | https://github.com/lun3x/wrapped_slab |
| max_upload_size | |
| id | 920269 |
| size | 16,678 |
Very simple Rust library useful when you want stronger type guarantees than Slab's usize keys. Generates TSlab(Slab<T>) that accepts TKey instead of usize. TVacantEntry(VacantEntry<T>) is also generated along the same lines. This should be a drop-in replacement for Slab<T>, provided all the keys are changed from usize to TKey.
use wrapped_slab::WrappedSlab;
#[derive(WrappedSlab)]
struct TestUnitStruct(String);
fn main() {
let mut slab = TestUnitStructSlab::default();
let key: TestUnitStructKey = slab.insert(TestUnitStruct("testing".into()));
let val: Option<&TestUnitStruct> = slab.get(key);
let next_entry: TestUnitStructVacantEntry = slab.vacant_entry();
let next_key: TestUnitStructKey = next_entry.key();
let next_entry_ref: &mut TestUnitStruct = next_entry.insert(TestUnitStruct(format!("{next_key:?}")));
// See wrapped_slab/tests/ for more examples
}