1 unstable release

0.0.1 Apr 17, 2024

#683 in #macro-derive

Download history 101/week @ 2024-04-11 40/week @ 2024-04-18

141 downloads per month
Used in xso

MPL-2.0 license

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:

  1. [syn] is used to parse the incoming TokenStream into a syn::Item. Based on that, the decision is made whether a struct or an enum is being derived on.

  2. Depending on the item type (enum vs. struct), a ItemDef object is created which implements that item. The actual implementations reside in crate::structs and crate::enums (respectively).

  3. 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.

  1. Enum variants and structs are processed using crate::compound::Compound, their fields being converted from crate::meta::XmlFieldMeta to crate::field::FieldDef. For enums, additional processing on the enum itself takes place in crate::enums. Likewise there's special handling for structs in crate::structs.

  2. If any wrapping was declared, the resulting ItemDef is wrapped using crate::wrapped.

  3. After all data has been structured, action is taken depending on the specific derive macro which has been invoked.

Dependencies

~285–730KB
~17K SLoC