The popular Rust crate for bidirectional maps, bimap, is limited to one-to-one relations (bijections) only (and appears unmaintained). But sometimes you need to have one-to-many and many-to-many relations, or have them made of arbitrary containers instead of having to always use either BTreeMap or HashMap.
I couldn't find anything for that, so I wrote my own Rust crate, multi_bimap:
github.com
GitHub - mikwielgus/multi_bimap: Many-to-many bidirectional map (aka. bipartite...
Many-to-many bidirectional map (aka. bipartite graph, relation) in Rust.
It's fully generic over its underlying containers (two antiparallel maps of sets), so you can have an arbitrary setup. You can e.g. have two hash maps of hash sets, or two B-tree maps of vecs. You are not limited to many-to-many relations, you can also have type-enforced one-to-one, one-to-many bimaps. You can have different types for the left-to-right and right-to-left constituent maps. You can use third-party collection types, e.g. indexmap::IndexMap as a constituent map and tinyvec::TinyVec as a constituent set. You can put keys inside Rc to avoid Clones for larger data.
This possible through a crate that I developed earlier, maplike, which provides common traits for collections and containers.
Here's a simple code example:
let mut produce: HashMultiBimap<&str, &str> = HashMultiBimap::new();
produce.insert("tomato", "red");
produce.insert("tomato", "fruit");
produce.insert("carrot", "orange");
produce.insert("carrot", "vegetable");
produce.insert("apple", "red");
produce.insert("apple", "fruit");
produce.insert("spinach", "green");
produce.insert("spinach", "vegetable");
assert_eq!(
produce.get_by_left("tomato"),
Some(&HashSet::from(["red", "fruit"])),
);
assert_eq!(
produce.get_by_right("fruit"),
Some(&HashSet::from(["tomato", "apple"])),
);
assert_eq!(
produce.get_by_right("vegetable"),
Some(&HashSet::from(["carrot", "spinach"])),
);
1 post - 1 participant
Read full topic
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | Maplike - Crate with traits for abstract containers and operations on them | 2 | 7 | 06-07-2026 |
| 2 | I wrote a small library for exclusive component filtering in bevy | 0 | 14.93 | 13-10-2026 |
| 3 | FerroProve - C-to-Rust lifter emitting #![forbid(unsafe_code)] crates with a differential oracle | 0 | 15.51 | 17-10-2026 |
| 4 | Loole 0.6.0: Improved correctness, performance and Flume compatibility | 0 | 9.4 | 14-10-2026 |
| 5 | [Project] sol: A self-contained browser kernel written in Rust | 0 | 9.76 | 18-10-2026 |
| 6 | Multicalc: Scientific computing for real time embedded systems in no_std rust | 0 | 9.4 | 28-07-2026 |
| 7 | Zaxis 0.0.5: immediate-mode GUI on wgpu, embeddable in a host's wgpu pass, with an real overlay layer for other processes | 0 | 10.2 | 11-10-2026 |
| 8 | Multicalc: Scientific computing for real-time embedded systems in no_std Rust | 0 | 14.36 | 10-08-2026 |
| 9 | Hotcode: easy to use hot-reload | 0 | 9.84 | 09-10-2026 |
| 10 | BloomCraft: twelve Bloom filter variants under one API, looking for feedback | 5 | 6 | 06-07-2026 |