err_convert_macro/
lib.rs

1//! Errors converting macros.
2
3#[macro_export]
4macro_rules! err_converter {
5    ( $a:ident, $b:ty ) => {
6        impl From<$b> for Error {
7            #[inline(always)]
8            fn from(e: $b) -> Self {
9                Error::$a(e)
10            }
11        }
12    };
13}
14
15#[macro_export]
16macro_rules! err_converter_no_args {
17    ( $a:ident, $b:ty ) => {
18        impl From<$b> for Error {
19            #[inline(always)]
20            fn from(_: $b) -> Self {
21                Error::$a
22            }
23        }
24    };
25}
26
27#[macro_export]
28macro_rules! err_converter_with_into {
29    ( $a:ident, $b:ty ) => {
30        impl From<$b> for Error {
31            #[inline(always)]
32            fn from(e: $b) -> Self {
33                Error::$a(e.into())
34            }
35        }
36    };
37}
38
39#[macro_export]
40macro_rules! err_convert_into_box {
41    () => {
42        impl From<Error> for Box<dyn std::error::Error + Send + Sync + 'static> {
43            #[inline(always)]
44            fn from(error: Error) -> Self {
45                use failure::Fail;
46                error.compat().into()
47            }
48        }
49    };
50}