1 unstable release
0.0.1 | Apr 17, 2024 |
---|
#683 in #macro-derive
141 downloads per month
Used in xso
220KB
4.5K
SLoC
Macros for parsing XML into Rust structs, and vice versa
If you are a user of xso_proc
or xso
, please
return to xso
for more information. The documentation of
xso_proc
is geared toward developers of …_macros
and …_core
.
You have been warned.
How the derive macros work
The processing is roughly grouped in the following stages:
-
[
syn
] is used to parse the incomingTokenStream
into asyn::Item
. Based on that, the decision is made whether a struct or an enum is being derived on. -
Depending on the item type (enum vs. struct), a
ItemDef
object is created which implements that item. The actual implementations reside incrate::structs
andcrate::enums
(respectively). -
The
crate::meta::XmlCompoundMeta
type is used to convert the raw token streams from the#[xml(..)]
attributes into structs/enums for easier handling.
That stage only does syntax checks, no (or just little) semantics. This
separation of concerns helps with simplifying the code both in meta
and the following modules.
-
Enum variants and structs are processed using
crate::compound::Compound
, their fields being converted fromcrate::meta::XmlFieldMeta
tocrate::field::FieldDef
. For enums, additional processing on the enum itself takes place incrate::enums
. Likewise there's special handling for structs incrate::structs
. -
If any wrapping was declared, the resulting
ItemDef
is wrapped usingcrate::wrapped
. -
After all data has been structured, action is taken depending on the specific derive macro which has been invoked.
Dependencies
~285–730KB
~17K SLoC