1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//! Macro implementation of the [thisctx](https://crates.io/crates/thisctx) crate.

#![allow(clippy::type_complexity)]

extern crate proc_macro;

mod ast;
mod attr;
mod expand;
mod generics;

use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};

#[proc_macro_derive(WithContext, attributes(error, source, thisctx))]
pub fn derive_with_context(input: TokenStream) -> TokenStream {
    let input = parse_macro_input!(input as DeriveInput);
    expand::derive(&input)
        .unwrap_or_else(|e| e.to_compile_error())
        .into()
}