I have the following structs:
struct Artist {
name: String,
image: String,
}
struct Album {
title: String,
artists: Vec<Artist>,
}
I need to produce XML that looks like:
<album>
<title>Some title</title>
<artist>
<name>Bonnie</name>
<image>http://example.com/bonnie.jpg</image>
</artist>
<artist>
<name>Cher</name>
<image>http://example.com/cher.jpg</image>
</artist>
</album>
How can I use serde to serialise/deserialise to the above XML format, specifically regarding flattening the artists
vector to produce multiple artist
elements? This is a third-party format I can't change :-(
The
serde-xml-rs
crate is the replacement for the deprecatedserde_xml
crate and supports serializing data structures to XML in the representation you want.The output is: