Skip to content

Commit a39aadb

Browse files
committed
Fix trait implementations on ItemIdentifier
1 parent 67f09bf commit a39aadb

File tree

1 file changed

+29
-1
lines changed
  • crates/header-translator/src

1 file changed

+29
-1
lines changed

crates/header-translator/src/id.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
use core::cmp::Ordering;
12
use core::fmt;
3+
use core::hash;
24

35
use clang::Entity;
46

@@ -20,7 +22,7 @@ impl ToOptionString for Option<String> {
2022
}
2123
}
2224

23-
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
25+
#[derive(Debug, Clone)]
2426
pub struct ItemIdentifier<N = String> {
2527
/// Names in Objective-C are global, so this is always enough to uniquely
2628
/// identify the item.
@@ -31,6 +33,32 @@ pub struct ItemIdentifier<N = String> {
3133
pub file_name: Option<String>,
3234
}
3335

36+
impl<N: PartialEq> PartialEq for ItemIdentifier<N> {
37+
fn eq(&self, other: &Self) -> bool {
38+
self.name == other.name
39+
}
40+
}
41+
42+
impl<N: Eq> Eq for ItemIdentifier<N> {}
43+
44+
impl<N: hash::Hash> hash::Hash for ItemIdentifier<N> {
45+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
46+
self.name.hash(state);
47+
}
48+
}
49+
50+
impl<N: Ord> PartialOrd for ItemIdentifier<N> {
51+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
52+
Some(self.cmp(other))
53+
}
54+
}
55+
56+
impl<N: Ord> Ord for ItemIdentifier<N> {
57+
fn cmp(&self, other: &Self) -> Ordering {
58+
self.name.cmp(&other.name)
59+
}
60+
}
61+
3462
impl<N: ToOptionString> ItemIdentifier<N> {
3563
pub fn from_raw(name: N, library: String) -> Self {
3664
Self {

0 commit comments

Comments
 (0)