dtolnay / serde-yaml

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

0.9 has less indentation of block sequence items inside a map #297

Closed tanavamsikrishna closed 2 years ago

tanavamsikrishna commented 2 years ago

This following sample code

#[derive(Serialize)]
struct Data {
    a: Vec<String>
}

# ---main---
let data = Data {
    a: vec!["row1".to_string(), "row2".to_string()]
};
let ser = serde_yaml::to_string(&data).unwrap();
assert_eq!(ser, "a:\n- row1\n- row2\n");

produces output: "a:\n- row1\n- row2\n" as the value of ser whereas the expected output is: "a:\n - row1\n - row2\n". Notice the 2 spaces before each vec item.

The current serialized output is improper as per yamllint linter

dtolnay commented 2 years ago

It's not clear to me that either one is more proper than the other. The YAML spec exclusively shows no leading space before the - in a map value, for example in https://yaml.org/spec/1.2.2/#example-mapping-scalars-to-sequences.

tanavamsikrishna commented 2 years ago

The standard seems to allow for both kinds of indentations. My actual concern is that the 0.9.* versions serializes data differently compared to the previous versions. So this broke my build.

Does this change originate from unsafe-libyaml? If you are convinced about unsafe-libyaml and intend to use it in future versions, sounds OK to me. Else it makes sense to conform to more objective criteria like passing yamllint lint tests.

edit: I see that the very underlying yaml parser library is libyaml published by yaml foundation itself.

dtolnay commented 2 years ago

My actual concern is that the 0.9.* versions serializes data differently compared to the previous versions.

It's intentional that 0.9 is not behaviorally identical to 0.8. I am sure this is not the only serialization difference between the two.