support enums whose unit variants serialize as something other than strings

Ouverte
#43 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
35/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
json, rust
Domaine
backend, devtools

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Rust
Étoiles
4
Forks
4
Merge moyen
15 h 16 min
PR mergées (30 j)
26

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de oxidecomputer/typespace

Toutes les issues de oxidecomputer/typespace

Issues similaires

Plus d'issues Rust

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.