A Rust library for containers built around 'generational id-s': tagged id-s which prevent errors caused by id reuse, id mixing (between different containers) and enable 'dangling id' detection (using an id after it was deleted).
Currently the only implemented type is IdVec
which is an unordered collection,
sometimes called a Slab
allocator. It differs from @carllerche's excellent
Slab in its support for the properties
described above at a small cost in memory and speed.
The particular implementation used for preventing ID reuse and mixing has some caveats (i.e. pathological cases causing false positives in membership tests) which mean you should not rely on it for memory safety or security. These cases are quite extreme so you're definitely OK to use this for video games etc. See the documentation for more details.
Add the dependency to your Cargo.toml
manifest.
```toml
[dependencies] idcontain = "0.1" ```
```rust extern crate idcontain;
use idcontain::{IdVec, Id};
fn main() { let mut idvecint1 = IdVec::new(); let mut idvecint2 = IdVec::withcapacity(3); let mut idvecstr = IdVec::withcapacity(1);
// Inserting an element returns its Id
.
let id1: Id
// Id-s are not reused. let id2 = idvecint1.insert(20); assert!(id2 != id1);
// Id-s from different IdVec
-s do not collide.
let id3 = idvecint2.insert(20);
assert!(id3 != id2);
assert!(id3 != id1);
// Id-s from IdVec
-s of different types cannot mixed with compile-time
// checks.
let strid: Id<&'static str> = idvecstr.insert("hello");
asserteq!(idvecstr[str_id], "hello")
// Compile-time errors: // strid == id1 // idvecint1.get(strid) // idvecstr[id1] } ```
Iteration and other stuff is also supported, check out the documentation!