Working with typetag for xs:choice / variant types?

オープン
#880 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
20/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
rust
領域
backend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Rust
スター
1.6k
フォーク
299
平均マージ
2日 4時間
マージ済み PR(30日)
9

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

tafia/quick-xml のほかの issue

tafia/quick-xml の issue をすべて見る

似ている issue

Rust の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。