Hello everyone! I'm currently busy writing an XML parsing and XSD code generation library in rust. I've gotten most features working however I'm now left with trying to add "substitution groups". Substitution groups (SGs from here) are groups of elements which can replace an existing element in a parent schema. In essence, you can think of it as a declaration of a subclass further down the chain.
Now, statically, this is simple by simply creating an enum of all known child elements that can substitute a specific parent element.
The problem becomes when you need this done dynamically - static typing no longer applies - you can take any data possible. In essence, sub-typing/class inheritance without any knowledge of it at compile time (this needs to be dynamic at runtime since the child schemas in this case need to be dynamic).
Basically what I'm trying to say is that this isn't a simple case, as far as I see I can't write it the rust way.
The options I see before me are:
- I have to do something like OOP
- Keeping the data in some kind of
Box<dyn ...> - Detecting a sub-class and keeping the data unserialized
Any ideas?