#key #dynamic #object

any_key

Dynamically typed keys for associative arrays

2 releases

Uses old Rust 2015

0.1.1 Nov 6, 2017
0.1.0 Aug 29, 2017

#2567 in Data structures

Download history 1136/week @ 2025-09-14 1424/week @ 2025-09-21 1198/week @ 2025-09-28 1250/week @ 2025-10-05 1044/week @ 2025-10-12 888/week @ 2025-10-19 828/week @ 2025-10-26 630/week @ 2025-11-02 621/week @ 2025-11-09 730/week @ 2025-11-16 1296/week @ 2025-11-23 749/week @ 2025-11-30 1119/week @ 2025-12-07

4,008 downloads per month
Used in 14 crates (4 directly)

MIT/Apache

9KB
177 lines

Dynamically typed keys for associative arrays.

Example

use std::collections::{BTreeMap, HashMap};
use any_key::{AnyHash, AnyOrd};

#[derive(PartialEq, Eq, Hash, PartialOrd, Ord)]
struct Foo;

// AnyHash can be used as a key for HashMap-like types
let mut map = HashMap::new();
map.insert(Box::new("hello") as Box<AnyHash>, 1);
map.insert(Box::new(42) as Box<AnyHash>, 2);
map.insert(Box::new(Foo) as Box<AnyHash>, 3);
assert_eq!(map.get(&(Box::new("hello") as Box<AnyHash>)), Some(&1));
assert_eq!(map.get(&(Box::new(42) as Box<AnyHash>)), Some(&2));
assert_eq!(map.get(&(Box::new(Foo) as Box<AnyHash>)), Some(&3));

// AnyOrd can be used as a key for HashMap-like types
let mut map = BTreeMap::new();
map.insert(Box::new("hello") as Box<AnyOrd>, 1);
map.insert(Box::new(42) as Box<AnyOrd>, 2);
map.insert(Box::new(Foo) as Box<AnyOrd>, 3);
assert_eq!(map.get(&(Box::new("hello") as Box<AnyOrd>)), Some(&1));
assert_eq!(map.get(&(Box::new(42) as Box<AnyOrd>)), Some(&2));
assert_eq!(map.get(&(Box::new(Foo) as Box<AnyOrd>)), Some(&3));

any_key

Documentation Crates.io Travis CI Build Status

Documentation for the master branch

Dynamically typed keys for associative arrays.

Dependencies

~33KB