compare TypedArenaPtr<T> by value not pointer (#1362)

This commit is contained in:
Mark Thom
2022-03-22 00:55:44 -06:00
parent d916da9ba8
commit 067e2633af
4 changed files with 33 additions and 22 deletions

View File

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