weak-table-rs: weak hash maps and sets for Rust

Build Status Crates.io License: MIT

This crate defines several kinds of weak hash maps and sets. See the full API documentation.

Usage

It’s on crates.io, so you can add

toml [dependencies] weak-table = "0.1.0"

to your Cargo.toml and

rust extern crate weak_table;

to your crate root.

Examples

Here we create a weak hash set and demonstrate that it forgets elements whose reference counts expire:

```rust use weak_table::WeakHashSet; use std::sync::{Arc, Weak};

type Table = WeakHashSet>;

let mut set = Table::new(); let a = Arc::new("a".tostring()); let b = Arc::new("b".tostring());

set.insert(a.clone());

assert!( set.contains("a") ); assert!( ! set.contains("b") );

set.insert(b.clone());

assert!( set.contains("a") ); assert!( set.contains("b") );

drop(a);

assert!( ! set.contains("a") ); assert!( set.contains("b") ); ```