1use ::core::borrow::Borrow;
2use alloc::string::String;
3use core::cmp::Ordering;
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
8#[derive(Debug, Default, Clone)]
9pub struct Pair<K, V> {
10 pub key: K,
11 pub value: V,
12}
13
14impl<K, V> Eq for Pair<K, V> where K: Ord {}
15
16impl<K, V> PartialEq<Self> for Pair<K, V>
17where
18 K: Ord,
19{
20 fn eq(&self, other: &Self) -> bool {
21 self.key.eq(&other.key)
22 }
23}
24
25impl<K, V> PartialOrd<Self> for Pair<K, V>
26where
27 K: Ord,
28{
29 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
30 Some(self.cmp(other))
31 }
32}
33
34impl<K, V> Ord for Pair<K, V>
35where
36 K: Ord,
37{
38 fn cmp(&self, other: &Self) -> Ordering {
39 self.key.cmp(&other.key)
40 }
41}
42
43impl<K, V> ::core::hash::Hash for Pair<K, V>
44where
45 K: ::core::hash::Hash,
46{
47 fn hash<H: ::core::hash::Hasher>(&self, state: &mut H) {
48 self.key.hash(state);
49 }
50}
51
52impl<K: Ord, V> Borrow<K> for Pair<K, V> {
53 fn borrow(&self) -> &K {
54 &self.key
55 }
56}
57
58impl<V> Borrow<str> for Pair<String, V> {
59 fn borrow(&self) -> &str {
60 self.key.as_str()
61 }
62}