Here are 3 structs: MainStruct, InnerStruct and MyEnum, and I want MainStruct to be serialized into a row in CSV, and it has a field which is Vec<InnerStruct>.
By default, Serde can't serialize it into CSV. It compiles correctly, but then outputs a serialization error.
I could use a #[serde(with=...)] macro and write a conversion of InnerStruct -> String. But it will require manual unpacking and will break if InnerStruct changes.
I tried using serialize_seq in my serialization code, but it fails the same way as without #[serde(with...)], when running.
Another option I tried was to run ..iter().map(|inner| inner.serialize(serializer)).collect().join(","), but serialize outputs a "serialization object", not a String.
I looked at making impl<...> Serialize<...> for Vec<InnerStruct> but it looks overly complicated.
I could write this encoding/decoding, but the real example has more fields, and feels like it'll be more tedious. That's why I'm asking if there's an elegant way.
CSV doesn't natively have a way to encode non-atomic nested values; it's for flat tables where every column is a simple value (number, string, missing, etc.)
Why do you expect an arbitrary serializer to output a String? That doesn't make much sense. Serializers are generic, there are many kinds of serializers for many formats (that's the point of Serde), and they can't just give you a string.
You can't impl Serialize for Vec because it's already implemented by Serde itself, so it would fail the coherence rules.
If you want that particular format, you'll have to implement it manually.
CSV doesn't natively have a way to encode non-atomic nested values
Tab Separated Values can do the work. Four years ago I wrote a crate named tsv. It utilize tabular data to represent hierarchical values, and can be viewed/edited in Excel. FYI.