support enums whose unit variants serialize as something other than strings

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

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

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

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
35/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
json, rust
領域
backend, devtools

調査の方向性

Start by reading how typespace represents enums and generates serialization code; the issue does not name specific files or tests. Trace how enum variants are represented and how generated code handles serde serialization and deserialization, then check the related Display and FromStr behavior. Done means typespace can represent variants serialized as arbitrary JSON values and generate the corresponding implementations.

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

説明

A schema like

{ "enum": [true, 1, "on"] }

has no representation in typespace today: an enum's unit variants serialize under their (renamed) Rust names, which are strings.

This isn't something serde annotations can express. External tagging is the only serde scheme that requires a unit variant's serialized value to be a string, and it's serde's default because it's the cheapest to deserialize; the other tagging forms don't help with a bare true or 1. So this takes two steps: typespace has to be able to represent a variant whose serialized form is an arbitrary JSON value, and then it has to generate Serialize and Deserialize impls for it.

Rather than treating these enums as special, my inclination is to generate the serde impls for all enums (or maybe all types). The argument for deriving is weaker than it looks: serde annotations don't appear in the docs, so the "familiar notation" benefit only reaches someone reading the generated source, and we already spend about as much effort organizing our structures to emit the right annotations as we would generating the impls directly.

Related: Display and FromStr for such an enum are the same gap seen from the other side, and should close with this.

主要言語
Rust
スター
4
フォーク
4
平均マージ
15時間 16分
マージ済み PR(30日)
26

環境構築

はじめの一歩

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

oxidecomputer/typespace のほかの issue

oxidecomputer/typespace の issue をすべて見る

似ている issue

Rust の issue をもっと見る

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

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