Skip to content

Commit

Permalink
add equal() methods for comparisons with other types
Browse files Browse the repository at this point in the history
  • Loading branch information
ajnirp committed Oct 21, 2015
1 parent 5e8dc36 commit d9f8f68
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion components/script/dom/bindings/js.rs
Expand Up @@ -251,6 +251,11 @@ impl<T: Reflectable> MutHeap<JS<T>> {
ptr::read(self.val.get()).root()
}
}

/// Compare this object to an `&T` value.
fn eq(&self, other: &T) -> bool {
self.get() == Root::from_ref(other)
}
}

impl<T: HeapGCValue> HeapSizeOf for MutHeap<T> {
Expand Down Expand Up @@ -325,6 +330,11 @@ impl<T: Reflectable> MutNullableHeap<JS<T>> {
*self.ptr.get() = val.map(|p| JS::from_ref(p));
}
}

/// Compare this object to an `Option<&T>` value.
fn equal(&self, other: Option<&T>) -> bool {
self.get() == other.map(|p| Root::from_ref(p))
}
}

impl<T: HeapGCValue> Default for MutNullableHeap<T> {
Expand All @@ -344,7 +354,7 @@ impl<T: HeapGCValue> HeapSizeOf for MutNullableHeap<T> {
}

impl<T: Reflectable> PartialEq for MutNullableHeap<JS<T>> {
fn eq(&self, other: &Self>) -> bool {
fn eq(&self, other: &Self) -> bool {
self.get().eq(&other.get())
}
}
Expand Down

0 comments on commit d9f8f68

Please sign in to comment.