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