mirror of
https://github.com/servo/servo.git
synced 2025-10-01 09:09:15 +01:00
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(); } } ````
This commit is contained in:
parent
e2fca1b228
commit
ad198993b1
6 changed files with 109 additions and 9 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -722,6 +722,10 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "dom_struct"
|
||||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"quote 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 0.14.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "domobject_derive"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue