Serde has a flatten
attribute which flattens one level of the data structure. I want the inverse: a way to group attributes.
I have the struct
struct Foo {
owner: Owner,
alpha: Server,
beta: Server,
}
and I want the servers to be serialized in a nested fashion, such:
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[servers]
[servers.alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[servers.beta]
ip = "10.0.0.2"
dc = "eqdc10"
by default Serde would produce:
[owner]
name = "Tom Preston-Werner"
dob = 1979-05-27T07:32:00-08:00 # First class dates
[alpha]
ip = "10.0.0.1"
dc = "eqdc10"
[beta]
ip = "10.0.0.2"
dc = "eqdc10"
Which I don't want. Is there a way to get the first YAML output without refactoring my struct?