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