Add a lifetime parameter to the ElementHelper trait

This refines the lifetime used in get_local_name / get_namespace and
makes it independent of the lifetime on the &self parameter.
This commit is contained in:
Cameron Zwarich 2014-09-30 20:33:40 -07:00
parent 4ef0f39c78
commit be9618d55b

View file

@ -237,26 +237,26 @@ impl LayoutElementHelpers for JS<Element> {
} }
} }
pub trait ElementHelpers { pub trait ElementHelpers<'a> {
fn html_element_in_html_document(self) -> bool; fn html_element_in_html_document(self) -> bool;
fn get_local_name<'a>(&'a self) -> &'a Atom; fn get_local_name(&self) -> &'a Atom;
fn get_namespace<'a>(&'a self) -> &'a Namespace; fn get_namespace(&self) -> &'a Namespace;
fn summarize(self) -> Vec<AttrInfo>; fn summarize(self) -> Vec<AttrInfo>;
fn is_void(self) -> bool; fn is_void(self) -> bool;
} }
impl<'a> ElementHelpers for JSRef<'a, Element> { impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
fn html_element_in_html_document(self) -> bool { fn html_element_in_html_document(self) -> bool {
let node: JSRef<Node> = NodeCast::from_ref(self); let node: JSRef<Node> = NodeCast::from_ref(self);
self.namespace == ns!(HTML) && node.is_in_html_doc() self.namespace == ns!(HTML) && node.is_in_html_doc()
} }
fn get_local_name<'a>(&'a self) -> &'a Atom { fn get_local_name(&self) -> &'a Atom {
&self.deref().local_name &self.extended_deref().local_name
} }
fn get_namespace<'a>(&'a self) -> &'a Namespace { fn get_namespace(&self) -> &'a Namespace {
&self.deref().namespace &self.extended_deref().namespace
} }
fn summarize(self) -> Vec<AttrInfo> { fn summarize(self) -> Vec<AttrInfo> {