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

Handle recursive types #164

Open
avantgardnerio opened this issue Apr 30, 2024 · 1 comment
Open

Handle recursive types #164

avantgardnerio opened this issue Apr 30, 2024 · 1 comment

Comments

@avantgardnerio
Copy link

avantgardnerio commented Apr 30, 2024

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> {
...
}
@avantgardnerio
Copy link
Author

I am by no means suggesting we merge without cleanup, but this fixes the problem:

#165

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant