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