2个版本

使用旧的Rust 2015

0.1.1 2017年11月6日
0.1.0 2017年8月29日

2343数据结构

Download history · Rust 包仓库 37/week @ 2024-04-01 · Rust 包仓库 5/week @ 2024-04-08 · Rust 包仓库 10/week @ 2024-04-15 · Rust 包仓库 14/week @ 2024-04-22 · Rust 包仓库 5/week @ 2024-04-29 · Rust 包仓库 11/week @ 2024-05-06 · Rust 包仓库 16/week @ 2024-05-13 · Rust 包仓库 12/week @ 2024-05-20 · Rust 包仓库 9/week @ 2024-05-27 · Rust 包仓库 14/week @ 2024-06-03 · Rust 包仓库 8/week @ 2024-06-10 · Rust 包仓库 5/week @ 2024-06-17 · Rust 包仓库 12/week @ 2024-06-24 · Rust 包仓库 34/week @ 2024-07-08 · Rust 包仓库 11/week @ 2024-07-15 · Rust 包仓库

每月下载 57
4 包(2个直接使用)中使用

MIT/Apache

9KB
177

any_key

Documentation Crates.io Travis CI Build Status

master 分支的文档

关联数组的动态类型键。


lib.rs:

关联数组的动态类型键。

示例

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));

依赖项

~32KB