Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert that DOM structs have the correct first field #21105

Merged
merged 1 commit into from Jul 3, 2018

Commits on Jul 3, 2018

  1. 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();
        }
    }
    ````
    Manishearth committed Jul 3, 2018
You can’t perform that action at this time.