Working with typetag for xs:choice / variant types?

Aperta
#880 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
20/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by reading quick-xml's Serde deserialization support for $value and how it handles element names and attributes, then compare that behavior with typetag's deserialization model. The issue provides no target file or test; first determine whether this combination is supported and what behavior should be added. Done means a documented answer or a concrete supported approach for deserializing varying element types.

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

Descrizione

question serde

This is a question, rather than an issue.

I'd like to use typetag or a similar crate along with quick-xml, to deserialize a sequence of varying elements without hardcoding all the possible variants in an enum.

<Data>
    <Foo a="abc" />
    <Foo a="def" />
    <Bar b="123" c="456">
        <BarChild />
    </Bar>
    <!-- other typetag'd elements can appear here -->
</Data>

Is there some way to make this work with typetag and quick-xml?

I tried:

#[derive(Deserialize)]
pub struct Document {
    #[serde(rename = "$value")]
    pub items: Vec<Box<dyn SceneLoadable>>,
}

#[typetag::deserialize]
pub(crate) trait SceneLoadable {}

But after encountering an element, it proceeds to try and interpret the attributes on that tag as type info, e.g.: Unknown variant @id, expected one of ..... (Edit: my apologies to the github user with username id, I mentioned them by mistake. Oops!)

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.