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

Publish some libyaml settings to Serializer #321

Closed
badicsalex opened this issue Sep 2, 2022 · 3 comments · Fixed by #322
Closed

Publish some libyaml settings to Serializer #321

badicsalex opened this issue Sep 2, 2022 · 3 comments · Fixed by #322

Comments

@badicsalex
Copy link

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

dtolnay commented Sep 2, 2022

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

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

Thanks for the very quick fix :)

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

Successfully merging a pull request may close this issue.

2 participants