weak-table 0.1.2

Weak hash maps and sets
Documentation

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

[dependencies]
weak-table = "0.1.2"

to your Cargo.toml and

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:

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

type Table = WeakHashSet<Weak<str>>;

let mut set = Table::new();
let a = Arc::<str>::from("a");
let b = Arc::<str>::from("b");

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") );