TL;DR - yaml-rust2 is the way to go.
You say, Many people however won't take their time to understand what that means. Ok, I did. I have discovered an interesting history behind the implementations of Yaml processing in Rust.
While stepping over serde-yaml soure code with debugger, I have finally arrived to some strange and ugly code, with pointers, with lots of unsafe
, something clearly autogenerated. After digging out more, I found that, indeed serdes-yaml 0.9 is internally relying on unsafe-libyaml version 0.2 that is auto-translated code of libyaml, a C library. I see no reason of using such a drastic approaches in the code that merely parses some text input. Among other things, this unsafe-libyaml is also set read only on GitHub so we have one more unmaintained package. In C.
I also found that there is an open source pure Rust YAML parser available, yaml_rust. The code of this parser have been sitting in GitHub for three years without development and looks like with the broken build as well. It still does. However it has been forked and continued as yaml_rust2. I do not know much about the reasons and people behind this forking. The yaml-rust2 fork really took off only on March this year and currently has 53,936 downloads on crates .io.
I initially assumed that unsafe-libyaml is some early hack from the dawn of Rust when lots of critical functionality was missing and the time was scarce. However going over Git history revealed for me the more mysterious story: serde-yaml has actually been using yaml-rust in the past! Yaml-rust has been replaced by the auto-translated C code on July 18, 2022, by dtolnay (see this commit). I am not sure why this has been done. There are three pull requests making these changes , but none of them has any kind of discussion. They were all both submitted and merged by dtolnay. There are also two closed issues related to this replacement but also without any discussion. Hence looks more like single sided decision of the maintainer which he obviously has right to make on his own project but there may still be various views towards the change itself.
As a result of all these findings, I am switching into yaml-rust2 and recommend others to do the same. Using this library may be a little bit less straightforward with less things happening automagically but anyway all migration only took for me less than an hour and this includes including learning yaml-rust2 from scratch. Not a big deal.
Sorry for all noise I created here about the alternative maintenance, I needed some forensic not just in the code of serde-yaml but also in few other projects to understand the actual situation. I do not longer recommed using my own fork of serdes-yaml. The amazing world of Free Software is still full of mysterious legends worth Linux vs Minix. And the world is full of wonderful problems waiting to be solved.
P.S. The first version of this posting included many hyperlinks documenting my findings, but as a new user I am only allowed to post two links per post so I was forced to remove most of them.
UPDATE: I suggest taking a look at serde-saphyr, which I implemented after the original project became unmaintained. It’s built on top of the serde-saphyr
parser, written in idiomatic Rust, and — surprisingly — turned out to be significantly faster, not slower. It currently provides only deserialization, but it supports native merge keys, nested enums, duplicate key rejection, and strongly avoids panicking on invalid syntax.