Serde and YAML-support status?

While I understand YAML not being the very first class format that a serialization tool must support. Surely JSON being the most wide used format.

But for human-written structured data, YAML seems like the first choice.
However, GitHub - dtolnay/serde-yaml: Strongly typed YAML library for Rust the "unique" implementation has been deprecated for close to one-year now (2024-03-25).

Is there any plan to take it over/adopt it? Or just write new implementation?

serde_yaml_ng is a maintained fork of serde_yaml. Just don't use serde_yml, people in the Rust community have described it as borderline ransomware, which I tend to agree with.

In the Rust ecosystem (starting with Cargo, but also the wider ecosystem), you'll see a high rate of TOML adoption in favour of YAML.

5 Likes

If you have a choice in the format, avoid YAML. It has some serious shortcomings with serde. When you use #[serde(flatten)] your data is first converted to a serde-internal format and it has to make its best guess as to what a string "is." If you have a type that deserialize as a string and then passes through another function, it might get converted to another intermediate type. E.g. 123 converts to an integer.

TOML also has problems. You can't represent u64 with it, and values outside the i64 range will fail at runtime.

1 Like

Yaml has many problems. See this: The yaml document from hell

4 Likes

@jofas thank you for the information! I will try to discuss with new maintainer about issue I have from the fork :slight_smile: Hope Serde community may update their page: Serde - Data formats.

@jofas I saw, but I never liked TOML. It's look like some a little improvement over INI format (with section-style). But always found (and it seems to be shared) to not really fit describing nested data structure.
And finally I also find out "hard" (not fluent?) to hand written. Which is my main purpose.
Surely, my (traumatic?) experience writting Traefik configuration file is speaking there.

@user16251 I have. But I decided it is common and well-known format. Being also compatible with JSON. Which can be easily generated from many sources if people wants to.
I might also consider JSON5.

@Segment7163 I know YAML have issues :slight_smile: There are known for years now. Mostly about non-quoted things. People may make mistakes one time, and usage should quickly tell them what's wrong. Finally configuration is fixed up.

TOML
the syntax is not as verbose as json

:smile:

Thanks all for information & feedback!

2 Likes

It's not so much that YAML has issues (it does!) but that serde has some long-standing issues with it:

It is possible to produce YAML and a Rust struct Foo so that deserializing to Foo succeeds, but deserializing into

#[derive(Deserialize)]
struct Bar {
    #[serde(flatten)]
    foo: Foo
}

fails.

JSON has similar problems but, but they are much harder to trip over, at least in my experience.

1 Like

I am not aware of any good tool that can enforce a sane yaml subset

(From the yaml document from hell article)

StrictYAML - HitchDev seems to be one such tool :slight_smile: just for people's awareness

1 Like