Skip to content

Commit fb0beb8

Browse files
committed
Unconditionally implement Ord for Handle
1 parent 2f409a8 commit fb0beb8

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

experiments/2024-12-09/src/geometry/operation.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{fmt, ops::Deref, rc::Rc};
1+
use std::{cmp::Ordering, fmt, ops::Deref, rc::Rc};
22

33
use super::tri_mesh::TriMesh;
44

@@ -29,7 +29,6 @@ impl fmt::Display for OperationDisplay<'_> {
2929
}
3030
}
3131

32-
#[derive(Ord, PartialOrd)]
3332
pub struct Handle<T> {
3433
inner: Rc<T>,
3534
}
@@ -74,12 +73,24 @@ impl<T> Deref for Handle<T> {
7473

7574
impl<T> Eq for Handle<T> {}
7675

76+
impl<T> Ord for Handle<T> {
77+
fn cmp(&self, other: &Self) -> Ordering {
78+
Rc::as_ptr(&self.inner).cmp(&Rc::as_ptr(&other.inner))
79+
}
80+
}
81+
7782
impl<T> PartialEq for Handle<T> {
7883
fn eq(&self, other: &Self) -> bool {
7984
Rc::ptr_eq(&self.inner, &other.inner)
8085
}
8186
}
8287

88+
impl<T> PartialOrd for Handle<T> {
89+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
90+
Some(self.cmp(other))
91+
}
92+
}
93+
8394
impl<T> fmt::Debug for Handle<T> {
8495
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8596
f.debug_struct("Handle")

0 commit comments

Comments
 (0)