Skip to content
This repository has been archived by the owner on Mar 25, 2024. It is now read-only.

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

Closed
tanavamsikrishna opened this issue Aug 1, 2022 · 3 comments
Closed

Comments

@tanavamsikrishna
Copy link

tanavamsikrishna commented Aug 1, 2022

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

@tanavamsikrishna tanavamsikrishna changed the title Improper indentations of serialized output of versions 0.9.* Improper indentations in serialized output of versions 0.9.* Aug 1, 2022
@dtolnay
Copy link
Owner

dtolnay commented Aug 1, 2022

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
Copy link
Author

tanavamsikrishna commented Aug 1, 2022

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 dtolnay changed the title Improper indentations in serialized output of versions 0.9.* 0.9 has less indentation of block sequence items inside a map Aug 1, 2022
@dtolnay
Copy link
Owner

dtolnay commented Aug 1, 2022

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants