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

Abierto
#68 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
57/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
backend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.
Lenguaje dominante
Rust
Estrellas
4
Forks
4
Merge medio
15 h 16 min
PR fusionados (30 d)
26

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de oxidecomputer/typespace

Todos los issues de oxidecomputer/typespace

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.