parco_xml_macros/
lib.rs

1use proc_macro::TokenStream;
2use syn::parse_macro_input;
3
4mod common;
5mod dexml;
6mod xml;
7
8/// Derives Deserialization Logic Via Custom DSL Templating
9///
10/// ## Borrow Syntax
11///
12/// ```rust,ignore
13/// // only one lifetime is allowed when borrowing data
14/// struct MyStruct<'a> {
15///     field: &'a str,
16///     captured_attr: &'a str,
17/// }
18///
19/// dexml! {
20///     // the ref keyword is for borrowing data
21///     ref MyStruct;
22///
23///     Response {
24///         // force an attribute to be a certain value or capture it
25///         Field id="required_id" other=(captured_attr) {
26///             // capture named fields via parens
27///             (field)
28///         }
29///     }
30/// }
31/// ```
32///
33/// ## Owned Syntax
34///
35/// ```rust,ignore
36/// dexml! {
37///     // the use keyword tells the macro you don't need a lifetime on your impl
38///     use MyStruct;
39///
40///     // your templating logic here
41/// }
42/// ```
43#[proc_macro]
44pub fn dexml(input: TokenStream) -> TokenStream {
45    common::out(dexml::handler(parse_macro_input!(input)))
46}
47
48/// Derives Serialization Logic Via Custom DSL Templating
49///
50/// ## Borrow Syntax
51///
52/// ```rust,ignore
53/// // you are only allowed one lifetime if you are borrowing
54/// struct MyStruct<'a> {
55///     field: &'a str,
56/// }
57///
58/// xml! {
59///     // the keyword ref tells the macro you are borrowing
60///     ref MyStruct;
61///     
62///     // define your namespaces here
63///     @ns {
64///         myns = "uri:myns",
65///     }
66///
67///     myns:Element attr=(self.field) {
68///         // parens allow you to write any expression
69///         (self.field)
70///     }
71/// }
72/// ```
73///
74/// ## Owned Syntax
75///
76/// ```rust,ignore
77///
78/// struct MyStruct {
79///     owned: String,
80/// }
81///
82/// xml! {
83///     // the use keyword means you aren't borrowing data
84///     use MyStruct;
85///
86///     // define your namespaces here
87///     @ns {
88///         myns = "uri:myns",    
89///     }
90///
91///     myns:Element {
92///         (self.owned)
93///     }
94/// }
95/// ```
96///
97#[proc_macro]
98pub fn xml(input: TokenStream) -> TokenStream {
99    common::out(xml::handler(parse_macro_input!(input)))
100}