[][src]Crate many_to_many

This is a very simple crate which you can use for creating many-to-many data structures in Rust, it's intended purpose or use case is for situations where you need to map a set of ids to another set of ids (for example in PubSub, such as hive_pubsub which is what this crate was designed for). It does this by using two HashMaps, one linking Left to a set of Right and vice-versa.

This crate is like a fusion of bimap and multimap. I didn't see anything like this on crates.io, or anywhere really so I made my own thing.

Constraints

Keys on either side (left or right) must implement the following traits:

Example

use many_to_many::ManyToMany;
 
let mut map = ManyToMany::new();
map.insert(1, 2);
map.insert(1, 3);
map.insert(1, 4);
 
dbg!(map.get_left(&1));
 
map.insert(5, 2);
map.remove(&1, &4);
 
dbg!(map.get_left(&1));
dbg!(map.get_right(&2));
 
map.remove(&1, &2);
map.remove(&1, &3);
 
assert_eq!(map.get_left(&1), None);

Structs

ManyToMany

Many-To-Many data structure.