Hello. The code at the bottom of the post has the struct "CompoundStruct" that is composed of two other structs. The code, as it's written, serializes into (in json):
Obviously I could reach inside struct_a and struct_b inside my serialize function for CompoundStruct, but I want to keep StructA and StructB as opaque as possible from the point of view of CompoundStruct. I don't mind if StructA and StructB have an awareness that they are serializing into a map, or a specialized function to serialize them into a map.
What do you suggest, that would be most in-line with the serde way of thinking?
Is definitely on the right track. However, it appears to work only for derived Serializers. For other reasons, I need to write a custom serializer function for CompoundStruct.
I'm not familiar enough with Rust to know if this is possible, but can Rust be made to dump out the derived functions so I can inspect them? Basically I want to see if it's calling some other serde interface, e.g. map.serialize_flattened_entries()
Note that this solution might break unexpectedly on minor Serde update, since this interface isn't really a part of public API (it is accessible only due to the fact that macros cannot reach private items). If you're creating an application and not a library, you might want to pin the version in Cargo.toml, by stating it as =1.x instead of 1.x.