mirror of
https://github.com/hannobraun/Fornjot
synced 2025-06-26 05:06:07 +00:00
commit
a3324f3ba3
@ -219,61 +219,24 @@ impl<T> Eq for HandleWrapper<T> {}
|
|||||||
|
|
||||||
impl<T> PartialEq for HandleWrapper<T> {
|
impl<T> PartialEq for HandleWrapper<T> {
|
||||||
fn eq(&self, other: &Self) -> bool {
|
fn eq(&self, other: &Self) -> bool {
|
||||||
// The purpose of `HandleWrapper` is to provide equality (and other
|
|
||||||
// traits) for `Handle<T>`s that would otherwise not have them. We use
|
|
||||||
// `Handle::id` to do this. This means, objects that are not identical
|
|
||||||
// are not equal.
|
|
||||||
//
|
|
||||||
// This is desirable for the most part, but it does become horribly
|
|
||||||
// inconvenient in test code. Tests, by design, create equal (but not
|
|
||||||
// identical) objects and compare them against objects produced by the
|
|
||||||
// code under test. Under such a use case, one would rather ignore any
|
|
||||||
// objects wrapped by `HandleWrapper`.
|
|
||||||
//
|
|
||||||
// And the following bit of code does just that. This might be a
|
|
||||||
// horrible hack that will comes back to bite us later (I honestly don't
|
|
||||||
// know), but it is certainly a very economical solution to this
|
|
||||||
// problem.
|
|
||||||
if cfg!(test) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.id().eq(&other.0.id())
|
self.0.id().eq(&other.0.id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Hash for HandleWrapper<T> {
|
impl<T> Hash for HandleWrapper<T> {
|
||||||
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
|
||||||
// This piece of code exists to keep this implementation in sync with
|
|
||||||
// the `PartialEq` implementation. See comment there.
|
|
||||||
if cfg!(test) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.id().hash(state);
|
self.0.id().hash(state);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Ord for HandleWrapper<T> {
|
impl<T> Ord for HandleWrapper<T> {
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
// This piece of code exists to keep this implementation in sync with
|
|
||||||
// the `PartialEq` implementation. See comment there.
|
|
||||||
if cfg!(test) {
|
|
||||||
return Ordering::Equal;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.id().cmp(&other.0.id())
|
self.0.id().cmp(&other.0.id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> PartialOrd for HandleWrapper<T> {
|
impl<T> PartialOrd for HandleWrapper<T> {
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
// This piece of code exists to keep this implementation in sync with
|
|
||||||
// the `PartialEq` implementation. See comment there.
|
|
||||||
if cfg!(test) {
|
|
||||||
return Some(Ordering::Equal);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.0.id().partial_cmp(&other.0.id())
|
self.0.id().partial_cmp(&other.0.id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user