servo/components/dom_struct/Cargo.toml
Manish Goregaokar ad198993b1 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();
    }
}
````
2018-07-03 09:39:29 -07:00

14 lines
250 B
TOML

[package]
authors = ["The Servo Project Developers"]
license = "MPL-2.0"
name = "dom_struct"
publish = false
version = "0.0.1"
[dependencies]
quote = "0.6.3"
syn = { version = "0.14.2", features = ["full"] }
[lib]
path = "lib.rs"
proc-macro = true