aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/bindings/inheritance.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2018-06-29 10:34:09 -0700
committerManish Goregaokar <manishsmail@gmail.com>2018-07-03 09:39:29 -0700
commitad198993b127ef87f129add8336f8bb7dfd30e4d (patch)
treedb1756c2241abbd068d81e4b07a4d481a55b5c73 /components/script/dom/bindings/inheritance.rs
parente2fca1b228ff20d54b67e0d1fa502b694b5c290e (diff)
downloadservo-ad198993b127ef87f129add8336f8bb7dfd30e4d.tar.gz
servo-ad198993b127ef87f129add8336f8bb7dfd30e4d.zip
Assert that DOM structs have the correct first field
DOM structs embed their parent type as their first field. This introduces a `.parent()` method to the DOM struct that returns its first field, and codegens a type assert that ensures that `.parent()` returns the parent struct. This generates: On `#[dom_struct]`: ```rust impl HasParent for Type { type Parent = ParentType; fn as_parent(&self) -> ParentType { &self.first_field } } ``` In the codegen files: ```rust impl Type { fn __assert_parent_type(&self) { let _: &ParentType = self.as_parent(); } } ````
Diffstat (limited to 'components/script/dom/bindings/inheritance.rs')
-rw-r--r--components/script/dom/bindings/inheritance.rs5
1 files changed, 5 insertions, 0 deletions
diff --git a/components/script/dom/bindings/inheritance.rs b/components/script/dom/bindings/inheritance.rs
index d97843bf42a..c017a806b6e 100644
--- a/components/script/dom/bindings/inheritance.rs
+++ b/components/script/dom/bindings/inheritance.rs
@@ -41,3 +41,8 @@ pub trait Castable: IDLInterface + DomObject + Sized {
}
}
}
+
+pub trait HasParent {
+ type Parent;
+ fn as_parent(&self) -> &Self::Parent;
+}