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

How to deserializes into generic struct that includes element name #778

Open
killercup opened this issue Jul 2, 2024 · 2 comments
Open
Labels
serde Issues related to mapping from Rust types to XML

Comments

@killercup
Copy link

I'm trying to parse MaterialX files like this one. They include "node graphs" which are a list of different elements with quite similar attributes and child elements.

As I don't know what elements to expect up front (they can be defined by external definition files), my idea was to have a generic Node struct and deserialize into that and then process it at a later stage. This works -- but I lose access to the element name. Is there a way to add it in as a field, e.g. using #[serde(rename = "$element-name")]?

If you can point me at the right place I'd be happy to make a PR.

@Mingun
Copy link
Collaborator

Mingun commented Jul 2, 2024

The what is you need is to have a DOM element. I started investigating this in my dom branch (it is outdated, but I have rebased version on my home computer, I'll push it when I get home (~10h later). There are no changes in functionality in the rebased version, although).

The second commit in that branch is a very early version of what should be done. Feel free to take it and finish the work. I planned to finish it, but not in the near future (there a many other improvements planned in the base Reader which takes my attention).

@Mingun
Copy link
Collaborator

Mingun commented Jul 23, 2024

In #383 author describes exactly this use case and said that it works.

@Mingun Mingun added the serde Issues related to mapping from Rust types to XML label Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
serde Issues related to mapping from Rust types to XML
Projects
None yet
Development

No branches or pull requests

2 participants