explicit_error_derive/
lib.rs

1extern crate proc_macro;
2extern crate proc_macro2;
3extern crate quote;
4extern crate syn;
5
6#[cfg(feature = "actix-web")]
7mod actix;
8#[cfg(any(feature = "exit", feature = "http"))]
9mod domain;
10
11#[cfg(any(feature = "http", feature = "exit", feature = "actix-web"))]
12use proc_macro::TokenStream;
13#[cfg(any(feature = "http", feature = "exit", feature = "actix-web"))]
14use syn::{DeriveInput, parse_macro_input};
15
16#[cfg(feature = "http")]
17#[proc_macro_derive(HttpError)]
18pub fn derive_http_error(input: TokenStream) -> TokenStream {
19    let input = parse_macro_input!(input as DeriveInput);
20
21    domain::derive(input, "explicit_error_http")
22        .unwrap_or_else(syn::Error::into_compile_error)
23        .into()
24}
25
26#[cfg(feature = "exit")]
27#[proc_macro_derive(ExitError)]
28pub fn derive_bin_error(input: TokenStream) -> TokenStream {
29    let input = parse_macro_input!(input as DeriveInput);
30
31    domain::derive(input, "explicit_error_exit")
32        .unwrap_or_else(syn::Error::into_compile_error)
33        .into()
34}
35
36#[cfg(feature = "actix-web")]
37#[proc_macro_derive(HandlerErrorHelpers)]
38pub fn derive_actix_handler_error(input: TokenStream) -> TokenStream {
39    let input = parse_macro_input!(input as DeriveInput);
40
41    actix::derive(input)
42        .unwrap_or_else(syn::Error::into_compile_error)
43        .into()
44}