parco_xml_macros/
lib.rs

1use proc_macro::TokenStream;
2use syn::parse_macro_input;
3
4mod common;
5mod xml;
6
7/// Derives Serialization Logic Via Custom DSL Templating
8///
9/// ## Borrow Syntax
10///
11/// ```rust,ignore
12/// // you are only allowed one lifetime if you are borrowing
13/// struct MyStruct<'a> {
14///     field: &'a str,
15/// }
16///
17/// xml! {
18///     // the keyword ref tells the macro you are borrowing
19///     ref MyStruct;
20///     
21///     // define your namespaces here
22///     @ns {
23///         myns = "uri:myns",
24///     }
25///
26///     myns:Element attr=(self.field) {
27///         // parens allow you to write any expression
28///         (self.field)
29///     }
30/// }
31/// ```
32///
33/// ## Owned Syntax
34///
35/// ```rust,ignore
36///
37/// struct MyStruct {
38///     owned: String,
39/// }
40///
41/// xml! {
42///     // the use keyword means you aren't borrowing data
43///     use MyStruct;
44///
45///     // define your namespaces here
46///     @ns {
47///         myns = "uri:myns",    
48///     }
49///
50///     myns:Element {
51///         (self.owned)
52///     }
53/// }
54/// ```
55///
56#[proc_macro]
57pub fn xml(input: TokenStream) -> TokenStream {
58    common::out(xml::handler(parse_macro_input!(input)))
59}