How to deserializes into generic struct that includes element name

Aperta
#778 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by reading the deserialization code and tests for mapping XML elements into structs; the issue does not name specific files or tests. Check whether the element name can be exposed as a field while preserving generic deserialization, then add a focused test using a MaterialX style node graph. Done means the deserialized node retains its element name and the test passes.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

serde

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.

Lingua principale
Rust
Stelle
1.6k
Fork
299
Merge medio
2g 4h
PR unite (30g)
9

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tafia/quick-xml

Tutte le issue di tafia/quick-xml

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.