1 | use crate::StdError; |
2 | use core::fmt::{self, Debug, Display}; |
3 | |
4 | #[repr (transparent)] |
5 | pub(crate) struct DisplayError<M>(pub(crate) M); |
6 | |
7 | #[repr (transparent)] |
8 | pub(crate) struct MessageError<M>(pub(crate) M); |
9 | |
10 | pub(crate) struct NoneError; |
11 | |
12 | impl<M> Debug for DisplayError<M> |
13 | where |
14 | M: Display, |
15 | { |
16 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
17 | Display::fmt(&self.0, f) |
18 | } |
19 | } |
20 | |
21 | impl<M> Display for DisplayError<M> |
22 | where |
23 | M: Display, |
24 | { |
25 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
26 | Display::fmt(&self.0, f) |
27 | } |
28 | } |
29 | |
30 | impl<M> StdError for DisplayError<M> where M: Display + 'static {} |
31 | |
32 | impl<M> Debug for MessageError<M> |
33 | where |
34 | M: Display + Debug, |
35 | { |
36 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
37 | Debug::fmt(&self.0, f) |
38 | } |
39 | } |
40 | |
41 | impl<M> Display for MessageError<M> |
42 | where |
43 | M: Display + Debug, |
44 | { |
45 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
46 | Display::fmt(&self.0, f) |
47 | } |
48 | } |
49 | |
50 | impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {} |
51 | |
52 | impl Debug for NoneError { |
53 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
54 | Debug::fmt(self:"Option was None" , f) |
55 | } |
56 | } |
57 | |
58 | impl Display for NoneError { |
59 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
60 | Display::fmt(self:"Option was None" , f) |
61 | } |
62 | } |
63 | |
64 | impl StdError for NoneError {} |
65 | |
66 | #[repr (transparent)] |
67 | pub(crate) struct BoxedError(pub(crate) Box<dyn StdError + Send + Sync>); |
68 | |
69 | impl Debug for BoxedError { |
70 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
71 | Debug::fmt(&self.0, f) |
72 | } |
73 | } |
74 | |
75 | impl Display for BoxedError { |
76 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
77 | Display::fmt(&self.0, f) |
78 | } |
79 | } |
80 | |
81 | impl StdError for BoxedError { |
82 | #[cfg (backtrace)] |
83 | fn backtrace(&self) -> Option<&crate::backtrace::Backtrace> { |
84 | self.0.backtrace() |
85 | } |
86 | |
87 | fn source(&self) -> Option<&(dyn StdError + 'static)> { |
88 | self.0.source() |
89 | } |
90 | } |
91 | |