imitate Rc-style equality for TypedArenaPtr (#1190)

This commit is contained in:
Mark Thom
2022-01-10 18:25:30 -07:00
parent ef0b239e70
commit f0e6b8ca47

View File

@@ -72,9 +72,17 @@ impl ArenaHeader {
} }
} }
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)] #[derive(Debug, PartialOrd, Ord)]
pub struct TypedArenaPtr<T: ?Sized>(ptr::NonNull<T>); pub struct TypedArenaPtr<T: ?Sized>(ptr::NonNull<T>);
impl<T: ?Sized + PartialEq> PartialEq for TypedArenaPtr<T> {
fn eq(&self, other: &TypedArenaPtr<T>) -> bool {
self.0 == other.0 || &**self == &**other
}
}
impl<T: ?Sized + PartialEq> Eq for TypedArenaPtr<T> {}
impl<T: ?Sized + Hash> Hash for TypedArenaPtr<T> { impl<T: ?Sized + Hash> Hash for TypedArenaPtr<T> {
#[inline(always)] #[inline(always)]
fn hash<H: Hasher>(&self, hasher: &mut H) { fn hash<H: Hasher>(&self, hasher: &mut H) {