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