bimap-rs is a two-way bijective map implementation for Rust.
To use bimap-rs in your Rust project, add the following to your Cargo.toml:
toml
bimap = "0.3"
serde compatibilitybimap-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 your Cargo.toml:
toml
bimap = { version = "0.3", features = [ "serde" ]}
no_std compatibilityTo use bimap-rs without the Rust standard library, add the following to your Cargo.toml:
toml
bimap = { version = "0.3", default-features = false }
Note that you'll need to use Rust nightly due to the use of the alloc feature.
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.
```rust 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) asserteq!(elements.getbyleft(&"bromine"), Some(&"Br")); asserteq!(elements.getbyleft(&"oxygen"), None);
// retrieve name by chemical symbol (right to left) asserteq!(elements.getbyright(&"C"), Some(&"carbon")); asserteq!(elements.getbyright(&"Al"), None);
// check membership assert!(elements.containsleft(&"hydrogen")); assert!(!elements.containsright(&"He"));
// remove elements asserteq!( elements.removebyleft(&"neodymium"), Some(("neodymium", "Nd")) ); asserteq!(elements.removebyright(&"Nd"), None);
// iterate over elements for (left, right) in &elements { println!("the chemical symbol for {} is {}", left, right); } ```
See the docs for more details.
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.