dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
964 stars 164 forks source link

Allow Configuration on Option::None handling #352

Open bnheise opened 1 year ago

bnheise commented 1 year ago

Currently if you have an optional field in Rust:

struct Something {
  maybe_not_there: Option<String>
}

Something {
  maybe_not_there: None
}

And you serialize it using this crate, you get this:

something
  maybe_not_there: null

However, valid yaml accepts also a tilde, no value at all, or simply omitting the key altogether.

Valid:

something
  maybe_not_there: ~

something
  maybe_not_there:

something

It would be nice if it were possible to configure the desired output.

nim65s commented 1 year ago

For the last option, ref. https://docs.rs/serde_with/3.0.0/serde_with/attr.skip_serializing_none.html