From d9f8f686155da67322bcaf8a654596af11b900eb Mon Sep 17 00:00:00 2001 From: Rohan Prinja Date: Thu, 22 Oct 2015 03:05:13 +0900 Subject: [PATCH] add equal() methods for comparisons with other types --- components/script/dom/bindings/js.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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 MutHeap> { 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 HeapSizeOf for MutHeap { @@ -325,6 +330,11 @@ impl MutNullableHeap> { *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 Default for MutNullableHeap { @@ -344,7 +354,7 @@ impl HeapSizeOf for MutNullableHeap { } impl PartialEq for MutNullableHeap> { - fn eq(&self, other: &Self>) -> bool { + fn eq(&self, other: &Self) -> bool { self.get().eq(&other.get()) } }