Skip to content

Commit

Permalink
Disambiguate methods without using trait objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Zwarich committed Oct 1, 2014
1 parent be9618d commit e894499
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 9 deletions.
24 changes: 21 additions & 3 deletions components/script/dom/element.rs
Expand Up @@ -966,10 +966,22 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
}
}
fn get_local_name<'b>(&'b self) -> &'b Atom {
(self as &ElementHelpers).get_local_name()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn get_local_name<'a, T: ElementHelpers<'a>>(this: T) -> &'a Atom {
this.get_local_name()
}

get_local_name(*self)
}
fn get_namespace<'b>(&'b self) -> &'b Namespace {
(self as &ElementHelpers).get_namespace()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn get_namespace<'a, T: ElementHelpers<'a>>(this: T) -> &'a Namespace {
this.get_namespace()
}

get_namespace(*self)
}
fn get_hover_state(&self) -> bool {
let node: JSRef<Node> = NodeCast::from_ref(*self);
Expand All @@ -993,6 +1005,12 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
node.get_enabled_state()
}
fn has_class(&self, name: &str) -> bool {
(self as &AttributeHandlers).has_class(name)
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn has_class<T: AttributeHandlers>(this: T, name: &str) -> bool {
this.has_class(name)
}

has_class(*self, name)
}
}
48 changes: 42 additions & 6 deletions components/script/dom/node.rs
Expand Up @@ -2036,27 +2036,63 @@ impl<'a> VirtualMethods for JSRef<'a, Node> {

impl<'a> style::TNode<'a, JSRef<'a, Element>> for JSRef<'a, Node> {
fn parent_node(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).parent_node().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn parent_node<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.parent_node()
}

parent_node(*self).map(|node| *node.root())
}

fn first_child(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).first_child().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn first_child<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.first_child()
}

first_child(*self).map(|node| *node.root())
}

fn prev_sibling(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).prev_sibling().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn prev_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.prev_sibling()
}

prev_sibling(*self).map(|node| *node.root())
}

fn next_sibling(&self) -> Option<JSRef<'a, Node>> {
(self as &NodeHelpers).next_sibling().map(|node| *node.root())
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn next_sibling<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> Option<Temporary<Node>> {
this.next_sibling()
}

next_sibling(*self).map(|node| *node.root())
}

fn is_document(&self) -> bool {
(self as &NodeHelpers).is_document()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn is_document<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool {
this.is_document()
}

is_document(*self)
}

fn is_element(&self) -> bool {
(self as &NodeHelpers).is_element()
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn is_element<'a, 'b, T: NodeHelpers<'a, 'b>>(this: T) -> bool {
this.is_element()
}

is_element(*self)
}

fn as_element(&self) -> JSRef<'a, Element> {
Expand Down

0 comments on commit e894499

Please sign in to comment.