dtolnay / serde-yaml

Strongly typed YAML library for Rust
Apache License 2.0
962 stars 158 forks source link

Publish some libyaml settings to Serializer #321

Closed badicsalex closed 2 years ago

badicsalex commented 2 years ago

I'd like to alter the formatting of my yml output files, most importantly the width of the output.

I think this could be done by exposing yaml_emitter_set_width from the Emitter, and then on the Serializer structure, so that I could do something like:

let mut ser = serde_yaml::Serializer::new(&mut buffer);
ser.set_width(-1);
my_data.serialize(&mut ser)?;

Would you accept a PR implementing something like this?

dtolnay commented 2 years ago

Could you give an example of a document where serializing with width=-1 makes a difference? It's possible that should just be default for all serializers.

badicsalex commented 2 years ago

My preferred format: https://github.com/badicsalex/hun_law_rs/blob/master/tests/datatests/data_convert_block_amendments/complex_1.yml#L38

This is how that part serializes since 0.9:

    - identifier: '13'
      children:
      - identifier: '1'
        body: A nukleáris létesítménnyel összefüggő hatósági engedélyezési
          eljárás során biztosítani kell a szakértőként eljáró személyek
          vagy szervezetek függetlenségét. Az egyes eljárásokban kirendelt,
          ...

There are no line breaks in my long strings.

width=-1 could be the default for sure, since that's how it worked up until 0.8 and I didn't see any complaints.

It seems like a taste thing though, because the line-broken version is generally easier to read, while in my case I usually don't care much about the actual content and gladly let it fall off the right side of the screen. Not line-breaking the strings also makes diffs cleaner.

badicsalex commented 2 years ago

Thanks for the very quick fix :)