Skip to content

A type-safe wrapper for Rust's "slab" data structure

Notifications You must be signed in to change notification settings

vi/slab_typesafe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

slab_typesafe

A type-safe wrapper from Rust's "slab" data structure

Prevents using slab with obviously wrong keys:

#[macro_use] 
extern crate slab_typesafe;

declare_slab_token!(StringHandle1);
declare_slab_token!(StringHandle2);

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`
```rust