YaSerDe
YaSerDe is a framework for serializing and deserializing Rust data structures efficiently and generically from and into XML.
YaSerDe makes it easy to serialize XML documents given an properly annotated struct.
Please refer to the examples
directory for the complete code shown below.
Serialize
For instance, let's say that one wants to generate a XML file for the Rust-Embedded community. A well known XML file for microcontrollers is called SVD and it can be defined on YaSerDe via structs like so:
use YaSerialize;
The interspersed #[yaserde()]
macros give some indication of what the resulting XML
Will look like, namely, a short snippet of the struct above in XML would be depending on
concrete values passed to the struct (not shown):
(...)
(...)
Notice the important difference in XML output representation between attributes
vs
child
, since SVD expects information in that particular arrangement. YaSerDe allows that
serialized XML to be valid unlike other Rust XML (de)serialization crates (i.e quick-xml).
Also the last DevAttrs
struct field is indeed another struct, so one can chain several
structs to compose the XML structure (again, see examples folder for the complete
example).
Be mindful that the Cargo.toml should not only include yaserde
and
yaserde_derive
, but also a few necessary dependencies... FIXME: THAT FOR SOME
USER-UNFRIENDLY REASON ARE NOT AUTOMATICALLY PULLED IN AS ONE WOULD EXPECT ;P ;P
... I'm sure there are good reasons, just wanted to leave this like this so that the author
can chip in and comment about the reasons behind that decision. ... I personally think that issue #22 should be reopened and fixed properly (as in only requiring yaserde as a dependency, adding yaserde_derive as a feature).
[]
# serde = { version = "1.0.123", features = [ "derive" ] }
# quick-xml = { version = "0.21.0", features = [ "serialize" ] }
= "0.5.1"
= "0.5.1"
= "0.8.3"
= "0.4"
Last but not least, in order to have a nice, pretty printed XML output one can do
PLEASE LET THE USERS KNOW HOW TO DO THAT CLEARLY ON YASERDE???
FIXME: For now I'm just resorting to online XML linters and formatters :_S