aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/js.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2014-12-06 02:12:24 -0800
committerManish Goregaokar <manishsmail@gmail.com>2014-12-06 02:51:52 -0800
commit5511e02a78a03c1e4f9fca422641aa9203859b3e (patch)
treef26469f5840c098b67315ba9e09fc09ca01eec1d /components/script/dom/bindings/js.rs
parente7b3caa386cfeedfd6f582a16575ba30f8ec87f2 (diff)
downloadservo-5511e02a78a03c1e4f9fca422641aa9203859b3e.tar.gz
servo-5511e02a78a03c1e4f9fca422641aa9203859b3e.zip
Add Comparable trait to js.rs; fixups
Diffstat (limited to 'components/script/dom/bindings/js.rs')
-rw-r--r--components/script/dom/bindings/js.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs
index f24115a349a..c9f3e157b75 100644
--- a/components/script/dom/bindings/js.rs
+++ b/components/script/dom/bindings/js.rs
@@ -575,3 +575,24 @@ impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> {
self.deref().reflector()
}
}
+
+/// A trait for comparing smart pointers ignoring the lifetimes
+pub trait Comparable<T> {
+ fn equals(&self, other: T) -> bool;
+}
+
+impl<'a, 'b, T> Comparable<JSRef<'a, T>> for JSRef<'b, T> {
+ fn equals(&self, other: JSRef<'a, T>) -> bool {
+ self.ptr == other.ptr
+ }
+}
+
+impl<'a, 'b, T> Comparable<Option<JSRef<'a, T>>> for Option<JSRef<'b, T>> {
+ fn equals(&self, other: Option<JSRef<'a, T>>) -> bool {
+ match (*self, other) {
+ (Some(x), Some(y)) => x.ptr == y.ptr,
+ (None, None) => true,
+ _ => false
+ }
+ }
+}