bimap-rs

Fast, generic bijective maps for Rust that feel like the standard library.

Library
Cargo
v0.6.3
150stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity0
Maintenance0
Community64
Maturity60
Momentum20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
83/100Excellent
Architecture82
Code Quality84
Innovation80
Learning Curve85

bimap-rs is a pure-Rust library for bijective maps — two-way mappings where every left value pairs with exactly one right value and vice versa. Published as the bimap crate, it offers hash-based (BiHashMap) and tree-based (BiBTreeMap) variants, has no required dependencies, and supports optional Serde serialization and no_std usage through feature flags.

What You Get

  • BiHashMap for O(1) average bidirectional lookups
  • BiBTreeMap for ordered, range-friendly bidirectional maps
  • Zero required dependencies with std enabled by default
  • Optional Serde and no_std support via feature flags

Common Use Cases

  • Maintaining a two-way mapping between IDs and names
  • Interning values while keeping a reverse lookup available
  • Associating enum variants with codes in both directions

Under The Hood

Architecture

The crate is organized around a shared design in lib.rs with two backends: hash.rs implements BiHashMap over standard HashMaps and btree.rs implements BiBTreeMap over BTreeMaps, both maintaining paired left-to-right and right-to-left indexes. mem.rs manages the shared-ownership storage that keeps the two directions consistent, and serde.rs provides optional (de)serialization.

Tech Stack

Pure Rust (edition 2018) with no required dependencies; serde is the only optional dependency, gated behind a feature flag. std is enabled by default but can be disabled for no_std targets.

Code Quality

The library is carefully engineered to mirror standard-library map ergonomics, with feature-gated serde and no_std paths and documentation hosted on docs.rs. Its clean module separation and focus on a single well-defined abstraction make the code approachable and dependable, backed by tens of millions of downloads.

API Design

The API mirrors HashMap and BTreeMap deliberately: insert pairs, then call get_by_left or get_by_right. Because the naming and semantics follow the standard library, existing Rust developers are productive almost immediately with minimal new concepts to learn.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search