serde-yaml icon indicating copy to clipboard operation
serde-yaml copied to clipboard

Unable to output single line array syntax

Open mabushey opened this issue 1 year ago • 2 comments

❤️ First off, serde is amazing. :)

I'm using serde_yaml::to_writer() to dump a struct to a yaml file. In the struct I have tmdb_genre: Vec<u64> which outputs like this:

tmdb_genre:
- 35
- 10751
- 9648
- 10749

While this is correct yaml, for purely aesthetic reasons I would like it to look like this:

tmdb_genre: [35, 10751, 9648, 10749]

I tried adding #[serde(flatten)] to the struct element but I get runtime Error("can only flatten structs and maps (got a sequence)"). Is there any way of doing this w/o resorting to post processing of the yaml (ie sed)? Thanks!

mabushey avatar Feb 23 '23 23:02 mabushey