1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use proc_macro::TokenStream;
use quote::quote;

#[proc_macro_derive(TonicError)]
pub fn tonic_error_derive(input: TokenStream) -> TokenStream {
    let ast = syn::parse(input).unwrap();
    impl_tonic_error(&ast)
}

fn impl_tonic_error(ast: &syn::DeriveInput) -> TokenStream {
    let name = &ast.ident;
    let gen = quote! {
        impl<'t> TonicError<'t> for #name {}
    };
    gen.into()
}