10 unstable releases (3 breaking)

✓ Uses Rust 2018 edition

0.4.0 Jul 31, 2019
0.3.1 Mar 23, 2019
0.2.0 Mar 6, 2019
0.1.5 Mar 8, 2018
0.1.3 Sep 13, 2017

#24 in Data structures

Download history 3270/week @ 2019-07-22 3149/week @ 2019-07-29 4188/week @ 2019-08-05 5102/week @ 2019-08-12 2740/week @ 2019-08-19 2909/week @ 2019-08-26 3109/week @ 2019-09-02 4295/week @ 2019-09-09 4394/week @ 2019-09-16 1386/week @ 2019-09-23 3274/week @ 2019-09-30 2539/week @ 2019-10-07 3707/week @ 2019-10-14 6568/week @ 2019-10-21 5183/week @ 2019-10-28

13,885 downloads per month
Used in 9 crates (3 directly)

Apache-2.0/MIT

78KB
1K SLoC

Build status Coverage Lines of code Version Documentation Downloads License Dependency status Rust version

bimap-rs

bimap-rs is a two-way bijective map implementation for Rust.

Usage

Installation

To use bimap-rs in your Rust project, add the following to the dependencies section of your Cargo.toml:

bimap = "0.4"

serde compatibility

bimap-rs optionally supports serialization and deserialization of BiHashMap and BiBTreeMap through serde. To avoid unnecessary dependencies, this is gated behind the serde feature and must be manually enabled. To do so, add the following to the dependencies section of your Cargo.toml:

bimap = { version = "0.4", features = [ "serde" ]}

no_std compatibility

To use bimap-rs without the Rust standard library, add the following the dependencies section of your Cargo.toml:

bimap = { version = "0.4", default-features = false }

If you do use bimap without the standard library, there is no BiHashMap, only BiBTreeMap. Currently, the no_std version of this library may not be used with serde integration.

Example

use bimap::BiMap;

let mut elements = BiMap::new();

// insert chemicals and their corresponding symbols
elements.insert("hydrogen", "H");
elements.insert("carbon", "C");
elements.insert("bromine", "Br");
elements.insert("neodymium", "Nd");

// retrieve chemical symbol by name (left to right)
assert_eq!(elements.get_by_left(&"bromine"), Some(&"Br"));
assert_eq!(elements.get_by_left(&"oxygen"), None);

// retrieve name by chemical symbol (right to left)
assert_eq!(elements.get_by_right(&"C"), Some(&"carbon"));
assert_eq!(elements.get_by_right(&"Al"), None);

// check membership
assert!(elements.contains_left(&"hydrogen"));
assert!(!elements.contains_right(&"He"));

// remove elements
assert_eq!(
    elements.remove_by_left(&"neodymium"),
    Some(("neodymium", "Nd"))
);
assert_eq!(elements.remove_by_right(&"Nd"), None);

// iterate over elements
for (left, right) in &elements {
    println!("the chemical symbol for {} is {}", left, right);
}

See the docs for more details.

License

bimap-rs is licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies