Skip to content

Handle recursive types #164

Open
Open
@avantgardnerio

Description

@avantgardnerio

When attempting to codegen for my xsd representing recursive widgets in a windowing environment, I get:

error[E0072]: recursive types `Grid`, `GridRow`, `Widget` and `WidgetChoice` have infinite size
  --> src/generated/models.rs:39:1
   |
39 | pub struct Grid {
   | ^^^^^^^^^^^^^^^
40 |     #[yaserde(rename = "children")]
41 |     pub children: GridRow,
   |                   ------- recursive without indirection
...
55 | pub struct GridRow {
   | ^^^^^^^^^^^^^^^^^^
56 |     #[yaserde(rename = "child")]
57 |     pub child: Widget,
   |                ------ recursive without indirection
...
78 | pub enum WidgetChoice {
   | ^^^^^^^^^^^^^^^^^^^^^
79 |     Grid(Grid),
   |          ---- recursive without indirection
...
94 | pub struct Widget {
   | ^^^^^^^^^^^^^^^^^
95 |     #[yaserde(flatten)]
96 |     pub widget_choice: WidgetChoice,
   |                        ------------ recursive without indirection
   |
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
   |
41 ~     pub children: Box<GridRow>,

I'm happy to start contributing, but a little help on where to get started here would help.

It seems like we would need to generate:

impl YaSerialize for Box<Grid> {
...
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions