1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
//! Derive custom errors using macros 1.1

extern crate proc_macro;
extern crate syn;
#[macro_use]
extern crate quote;
extern crate case;

mod error;

use error::Error;
use proc_macro::TokenStream;

#[proc_macro_derive(Error, attributes(error))]
pub fn derive_error(input: TokenStream) -> TokenStream {
    let source = input.to_string();
    let ast = syn::parse_macro_input(&source).expect("failed to parse the error defination");
    Error::new(ast)
        .derive()
        .parse()
        .expect("failed to parse the derived output")
}