A type-safe wrapper for slab.
It implements the same data structure with the same methods,
but takes and returns special tokens instead of usize values,
preventing you from confusing them with other unrelated usizes,
including keys for other Slab instances.
The protection is shallow, as the tokens implement From and Into.
Additionally, entire slab may be converted back and forth between wrapped typesafe
and unwrapped usize versions.
Based on compactmap::wrapped
Examples
Basic storing and retrieval.
extern crate slab_typesafe;
# use *;
declare_slab_token!;
#
Error if you confused the handles
#[macro_use]
extern crate slab_typesafe;
# use slab_typesafe::*;
declare_slab_token!(StringHandle1);
declare_slab_token!(StringHandle2);
# fn main(){
let mut slab1 : Slab<StringHandle1, _> = Slab::new();
let mut slab2 : Slab<StringHandle2, _> = Slab::new();
let hello = slab1.insert("hello");
let world = slab2.insert("world");
slab1[world]; // the type `Slab<StringHandle1, _>` cannot be indexed by `StringHandle2`
slab2.remove(hello); // expected struct `StringHandle2`, found struct `StringHandle1`
# }
See the rest of examples in the original documentation.
The documentation is mostly a copy of the original crate's documentation.