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