From 8334942d0c5c70fef5172010ee690094b44d215e Mon Sep 17 00:00:00 2001 From: Cameron Zwarich Date: Fri, 26 Sep 2014 15:28:59 -0700 Subject: [PATCH] Add an extended_deref method to JSRef The extended_deref method will take a JSRef<'a, T> and produce an &'a T, in contrast to the standard deref method that takes an &'b JSRef<'a, T> and produces an &'a T. This is useful when avoiding passing a JSRef by reference. --- components/script/dom/bindings/js.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 3fff9445c3c..110b5c57df5 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -493,6 +493,14 @@ impl<'a,T> JSRef<'a,T> { } } +impl<'a, T: Reflectable> JSRef<'a, T> { + pub fn extended_deref(self) -> &'a T { + unsafe { + &*self.ptr + } + } +} + impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> { fn reflector<'a>(&'a self) -> &'a Reflector { self.deref().reflector()