|
13 | 13 | // limitations under the License. |
14 | 14 |
|
15 | 15 | use std::borrow::Cow; |
16 | | -use std::cmp::Ordering; |
17 | 16 | use std::fmt::Display; |
18 | 17 | use std::fmt::Formatter; |
19 | | -use std::hash::Hash; |
20 | | -use std::hash::Hasher; |
21 | 18 |
|
22 | 19 | use nom::branch::alt; |
23 | 20 | use nom::character::complete::char; |
@@ -53,90 +50,6 @@ pub enum KeyPath<'a> { |
53 | 50 | Name(Cow<'a, str>), |
54 | 51 | } |
55 | 52 |
|
56 | | -impl Eq for KeyPaths<'_> {} |
57 | | - |
58 | | -impl PartialEq for KeyPaths<'_> { |
59 | | - fn eq(&self, other: &Self) -> bool { |
60 | | - let result = self.cmp(other); |
61 | | - result == Ordering::Equal |
62 | | - } |
63 | | -} |
64 | | - |
65 | | -impl PartialOrd for KeyPaths<'_> { |
66 | | - fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
67 | | - Some(self.cmp(other)) |
68 | | - } |
69 | | -} |
70 | | - |
71 | | -impl Ord for KeyPaths<'_> { |
72 | | - fn cmp(&self, other: &Self) -> Ordering { |
73 | | - for (self_path, other_path) in self.paths.iter().zip(other.paths.iter()) { |
74 | | - let ord = self_path.cmp(other_path); |
75 | | - if ord != Ordering::Equal { |
76 | | - return ord; |
77 | | - } |
78 | | - } |
79 | | - self.paths.len().cmp(&other.paths.len()) |
80 | | - } |
81 | | -} |
82 | | - |
83 | | -impl Eq for KeyPath<'_> {} |
84 | | - |
85 | | -impl PartialEq for KeyPath<'_> { |
86 | | - fn eq(&self, other: &Self) -> bool { |
87 | | - let ord = self.cmp(other); |
88 | | - ord == Ordering::Equal |
89 | | - } |
90 | | -} |
91 | | - |
92 | | -impl PartialOrd for KeyPath<'_> { |
93 | | - fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
94 | | - Some(self.cmp(other)) |
95 | | - } |
96 | | -} |
97 | | - |
98 | | -impl Ord for KeyPath<'_> { |
99 | | - fn cmp(&self, other: &Self) -> Ordering { |
100 | | - match (self, other) { |
101 | | - (KeyPath::Index(v1), KeyPath::Index(v2)) => v1.cmp(v2), |
102 | | - ( |
103 | | - KeyPath::QuotedName(v1) | KeyPath::Name(v1), |
104 | | - KeyPath::QuotedName(v2) | KeyPath::Name(v2), |
105 | | - ) => v1.cmp(v2), |
106 | | - (KeyPath::QuotedName(_) | KeyPath::Name(_), KeyPath::Index(_)) => Ordering::Greater, |
107 | | - (KeyPath::Index(_), KeyPath::QuotedName(_) | KeyPath::Name(_)) => Ordering::Less, |
108 | | - } |
109 | | - } |
110 | | -} |
111 | | - |
112 | | -impl Hash for KeyPath<'_> { |
113 | | - fn hash<H: Hasher>(&self, state: &mut H) { |
114 | | - match self { |
115 | | - KeyPath::Index(idx) => { |
116 | | - // Hash a discriminant to distinguish from other variants |
117 | | - 0_u8.hash(state); |
118 | | - idx.hash(state); |
119 | | - } |
120 | | - KeyPath::QuotedName(name) => { |
121 | | - // Hash a discriminant to distinguish from other variants |
122 | | - 1_u8.hash(state); |
123 | | - name.hash(state); |
124 | | - } |
125 | | - KeyPath::Name(name) => { |
126 | | - // Hash a discriminant to distinguish from other variants |
127 | | - 2_u8.hash(state); |
128 | | - name.hash(state); |
129 | | - } |
130 | | - } |
131 | | - } |
132 | | -} |
133 | | - |
134 | | -impl Hash for KeyPaths<'_> { |
135 | | - fn hash<H: Hasher>(&self, state: &mut H) { |
136 | | - self.paths.hash(state); |
137 | | - } |
138 | | -} |
139 | | - |
140 | 53 | impl Display for KeyPaths<'_> { |
141 | 54 | fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { |
142 | 55 | write!(f, "{{")?; |
|
0 commit comments