I've seen a question similar to this one, but no one that tells me exactly how to implement Ord
for a struct. For example, the following:
struct SomeNum {
name: String,
value: u32,
}
impl Ord for SomeNum {
fn cmp(&self, other:&Self) -> Ordering {
let size1 = self.value;
let size2 = other.value;
if size1 > size2 {
Ordering::Less
}
if size1 < size2 {
Ordering::Greater
}
Ordering::Equal
}
}
This gives me the error:
error: the trait `core::cmp::Eq` is not implemented for the type `SomeNum` [E0277]
How would I fix this? I have tried changing the implementation to:
impl Ord for SomeNum where SomeNum: PartialOrd + PartialEq + Eq {...}
and adding the appropriate partial_cmp
and eq
functions but it gives me the error that both those methods are not a member of Ord
.