add a setting to be less fussy about `Option` fields where `null` is not allowed

Aperta
#68 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
57/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by reading the code that renders optional properties as Rust Option<T> fields and the tests covering their generated serde attributes. Add the optional_value setting with RejectNull as the default and AllowNull producing a plain Option<T> with the skip attribute. Done when tests confirm both variants generate the described code.

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

Descrizione

An Optional property (whose type is not an Option, a container, or the
unit type) renders as Option<T> with deserialize_some:

#[serde(
    default,
    deserialize_with = "::json_serde::deserialize_some",
    skip_serializing_if = "::std::option::Option::is_none"
)]
pub value: ::std::option::Option<i64>,

An absend field serializes as None and null is an error. And that's
accurate! While a bare Option<T> permits null, an Optional property is
merely optional, not nullable.

However, not all people are quite as fussy, and they're used to reading
imprecise Rust code that looks like this:

#[serde(skip_serializing_if = "Option::is_none")]
pub value: Option<i64>,

To produce code more like that, we can add a setting: optional_value with two
variants:

  • RejectNull: the rendering above. Precise, accurate and the default; it's
    what typespace does today.
  • AllowNull: a plain Option<T> with just the skip, which is serde's own
    behavior--absent and null are both None.
Lingua principale
Rust
Stelle
4
Fork
4
Merge medio
15h 16m
PR unite (30g)
26

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 oxidecomputer/typespace

Tutte le issue di oxidecomputer/typespace

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.