aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src/lib.rs
blob: 4b96e17aaac2017a474a292dea65551af2b3e171 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
extern crate askama;
extern crate proc_macro;
extern crate syn;

use proc_macro::TokenStream;

#[proc_macro_derive(Template, attributes(template))]
pub fn derive_template(input: TokenStream) -> TokenStream {
    let ast = syn::parse_derive_input(&input.to_string()).unwrap();
    match ast.body {
        syn::Body::Struct(ref data) => data,
        _ => panic!("#[derive(Template)] can only be used with structs"),
    };
    askama::build_template(&ast).parse().unwrap()
}