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

未关闭
#68 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
57/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
rust
领域
backend

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
Rust
星标
4
派生
4
平均合并
15 小时 16 分钟
30 天内合并 PR
26

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

oxidecomputer/typespace 的其他 Issue

查看 oxidecomputer/typespace 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。