slab_typesafe 0.1.3

A wrapper for Slab that provides type-safe tokens instead of usize.
Documentation
  • Coverage
  • 100%
    33 out of 33 items documented26 out of 33 items with examples
  • Size
  • Source code size: 28.77 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.49 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • vi/slab_typesafe
    5 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vi

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