Unconditionally implement Ord for Handle

This commit is contained in:
Hanno Braun 2025-02-10 20:18:38 +01:00
parent 2f409a8b15
commit fb0beb8572

View File

@ -1,4 +1,4 @@
use std::{fmt, ops::Deref, rc::Rc}; use std::{cmp::Ordering, fmt, ops::Deref, rc::Rc};
use super::tri_mesh::TriMesh; use super::tri_mesh::TriMesh;
@ -29,7 +29,6 @@ impl fmt::Display for OperationDisplay<'_> {
} }
} }
#[derive(Ord, PartialOrd)]
pub struct Handle<T> { pub struct Handle<T> {
inner: Rc<T>, inner: Rc<T>,
} }
@ -74,12 +73,24 @@ impl<T> Deref for Handle<T> {
impl<T> Eq for Handle<T> {} impl<T> Eq for Handle<T> {}
impl<T> Ord for Handle<T> {
fn cmp(&self, other: &Self) -> Ordering {
Rc::as_ptr(&self.inner).cmp(&Rc::as_ptr(&other.inner))
}
}
impl<T> PartialEq for Handle<T> { impl<T> PartialEq for Handle<T> {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
Rc::ptr_eq(&self.inner, &other.inner) Rc::ptr_eq(&self.inner, &other.inner)
} }
} }
impl<T> PartialOrd for Handle<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<T> fmt::Debug for Handle<T> { impl<T> fmt::Debug for Handle<T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_struct("Handle") f.debug_struct("Handle")