3个稳定版本
| 1.0.2 | 2023年6月5日 |
|---|
#2690 在 数据库接口
5KB
79 行
kvp
这个crate旨在提供一个类型KeyValuePair<TKey, TValue>,当有人希望用额外的数据“标记”一个值,同时保持其功能特性(PartialEq、Eq、PartialOrd、Ord、Hash)完全依赖于键,而不考虑标记的数据。这可以用来,例如,有一个更类似于HashMap的BinaryHeap,在存储键值数据方面的能力。
let heap = BinaryHeap::new();
heap.push(KeyValuePair { key: 50, value: "Hey, here's an associated value" })
// You can also use ::new syntax
heap.push(KeyValuePair::new(0, "another bit of associated data!"));
heap.push(KeyValuePair::new(22, "voila"));
assert_matches!(heap.pop(), Some(50));
assert_matches!(heap.pop(), Some(22));
assert_matches!(heap.pop(), Some(0));