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.
This commit is contained in:
Cameron Zwarich 2014-09-26 15:28:59 -07:00
parent 1e5770a138
commit 8334942d0c

View file

@ -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()