wrapper.rs
This file
Path
src/wrapper.rs
78 lines · 1.6 KiB · Rust
Last changed by
Merge pull request #53 from dtolnay/nostdDavid Tolnaybefore adoption55343b9
History of this fileTake it
1use crate::StdError;2use core::fmt::{self, Debug, Display};34#[repr(transparent)]5pub struct MessageError<M>(pub M);67impl<M> Debug for MessageError<M>8where9 M: Display + Debug,10{11 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {12 Debug::fmt(&self.0, f)13 }14}1516impl<M> Display for MessageError<M>17where18 M: Display + Debug,19{20 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {21 Display::fmt(&self.0, f)22 }23}2425impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {}2627#[repr(transparent)]28pub struct DisplayError<M>(pub M);2930impl<M> Debug for DisplayError<M>31where32 M: Display,33{34 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {35 Display::fmt(&self.0, f)36 }37}3839impl<M> Display for DisplayError<M>40where41 M: Display,42{43 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {44 Display::fmt(&self.0, f)45 }46}4748impl<M> StdError for DisplayError<M> where M: Display + 'static {}4950#[cfg(feature = "std")]51#[repr(transparent)]52pub struct BoxedError(pub Box<dyn StdError + Send + Sync>);5354#[cfg(feature = "std")]55impl Debug for BoxedError {56 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {57 Debug::fmt(&self.0, f)58 }59}6061#[cfg(feature = "std")]62impl Display for BoxedError {63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {64 Display::fmt(&self.0, f)65 }66}6768#[cfg(feature = "std")]69impl StdError for BoxedError {70 #[cfg(backtrace)]71 fn backtrace(&self) -> Option<&crate::backtrace::Backtrace> {72 self.0.backtrace()73 }7475 fn source(&self) -> Option<&(dyn StdError + 'static)> {76 self.0.source()77 }78}