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

Offen
#68 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
57/100
Issue-Typ
Feature
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
rust
Bereich
backend

Rechercherichtung

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.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

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.
Vorherrschende Sprache
Rust
Sterne
4
Forks
4
Ø Merge
15 Std. 16 Min.
Gemergte PRs (30 T.)
26

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus oxidecomputer/typespace

Alle Issues in oxidecomputer/typespace

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.