diff options
Diffstat (limited to 'components/script/dom/bindings/inheritance.rs')
-rw-r--r-- | components/script/dom/bindings/inheritance.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/components/script/dom/bindings/inheritance.rs b/components/script/dom/bindings/inheritance.rs index 920ecb07397..c9ccdbd0325 100644 --- a/components/script/dom/bindings/inheritance.rs +++ b/components/script/dom/bindings/inheritance.rs @@ -15,20 +15,25 @@ use std::mem; /// or are derived from other interfaces. pub trait Castable: IDLInterface + Reflectable + Sized { /// Check whether a DOM object implements one of its deriving interfaces. - fn is<T>(&self) -> bool where T: DerivedFrom<Self> { - let class = unsafe { - get_dom_class(self.reflector().get_jsobject().get()).unwrap() - }; + fn is<T>(&self) -> bool + where T: DerivedFrom<Self> + { + let class = unsafe { get_dom_class(self.reflector().get_jsobject().get()).unwrap() }; T::derives(class) } /// Cast a DOM object upwards to one of the interfaces it derives from. - fn upcast<T>(&self) -> &T where T: Castable, Self: DerivedFrom<T> { + fn upcast<T>(&self) -> &T + where T: Castable, + Self: DerivedFrom<T> + { unsafe { mem::transmute(self) } } /// Cast a DOM object downwards to one of the interfaces it might implement. - fn downcast<T>(&self) -> Option<&T> where T: DerivedFrom<Self> { + fn downcast<T>(&self) -> Option<&T> + where T: DerivedFrom<Self> + { if self.is::<T>() { Some(unsafe { mem::transmute(self) }) } else { |