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 HashMap
s, 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.
Keys on either side (left or right) must implement Hash, Eq and Clone. See documentation for more information.
Example
use ManyToMany;
let mut map = new;
map.insert;
map.insert;
map.insert;
assert_eq_sorted;
map.insert;
map.remove;
assert_eq_sorted;
assert_eq_sorted;
map.remove;
map.remove;
assert_eq!;
map.insert;
map.insert;
map.insert;
map.remove_right;
assert_eq!;
assert_eq!;
/// This is a helper function to unwrap the option,
/// sort the array and compare it with a sorted array.
Serde support
This crate has optional Serde support. To enable it, specify the serde
feature in Cargo.toml
. For example:
[]
= { = "^0.1.7", = ["serde"] }