explicit_error_derive/
lib.rs1extern crate proc_macro;
2extern crate proc_macro2;
3extern crate quote;
4extern crate syn;
5
6#[cfg(any(feature = "exit", feature = "http"))]
7mod domain;
8#[cfg(feature = "http")]
9mod http;
10
11#[cfg(any(feature = "http", feature = "exit"))]
12use proc_macro::TokenStream;
13#[cfg(any(feature = "http", feature = "exit"))]
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 = "http")]
37#[proc_macro_derive(HandlerErrorHelpers)]
38pub fn derive_actix_handler_error(input: TokenStream) -> TokenStream {
39 let input = parse_macro_input!(input as DeriveInput);
40 http::derive(input).into()
41}