webframework_core/
error.rs

1#[macro_export]
2macro_rules! impl_fail_boilerplate {
3    ($kind:ident, $error:ident) => {
4        impl failure::Fail for $error {
5            fn cause(&self) -> Option<&failure::Fail> {
6                self.inner.cause()
7            }
8
9            fn backtrace(&self) -> Option<&failure::Backtrace> {
10                self.inner.backtrace()
11            }
12        }
13
14        impl $error {
15            pub fn kind(&self) -> $kind {
16                self.inner.get_context().to_owned()
17            }
18        }
19
20        impl From<$kind> for $error {
21            fn from(kind: $kind) -> $error {
22                $error { inner: Context::new(kind) }
23            }
24        }
25
26        impl From<Context<$kind>> for $error {
27            fn from(inner: Context<$kind>) -> $error {
28                $error { inner: inner }
29            }
30        }
31
32        impl std::fmt::Display for $error {
33            fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
34                std::fmt::Display::fmt(&self.inner, f)
35            }
36        }
37    }
38}