diff options
author | Rohan Prinja <rohan.prinja@gmail.com> | 2015-10-22 03:05:13 +0900 |
---|---|---|
committer | Rohan Prinja <rohan.prinja@gmail.com> | 2015-10-22 03:05:13 +0900 |
commit | d9f8f686155da67322bcaf8a654596af11b900eb (patch) | |
tree | 8f9cb7c3cb2bbf256fca670c6ae2116824a5e820 /components/script | |
parent | 5e8dc366debdaac349b7aba204f29c53dfb1f827 (diff) | |
download | servo-d9f8f686155da67322bcaf8a654596af11b900eb.tar.gz servo-d9f8f686155da67322bcaf8a654596af11b900eb.zip |
add equal() methods for comparisons with other types
Diffstat (limited to 'components/script')
-rw-r--r-- | components/script/dom/bindings/js.rs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 5e8ce0d731d..3e4cfeb0fce 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -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> { @@ -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> { @@ -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()) } } |