Working with typetag for xs:choice / variant types?

Abierto
#880 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
20/100
Tipo de issue
Nueva funcionalidad
Claridad
Necesita aclaración
Estado de actividad
Estancado
Stack tecnológico
rust
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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!)

Lenguaje dominante
Rust
Estrellas
1.6k
Forks
299
Merge medio
2 d 4 h
PR fusionados (30 d)
9

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tafia/quick-xml

Todos los issues de tafia/quick-xml

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.