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
Merge pull request #53 from dtolnay/nostdDavid Tolnaybefore adoption55343b9
lines 1–2why, one step back1use crate::StdError;2use core::fmt::{self, Debug, Display};Move transparent wrapper errors to own moduleDavid Tolnaybefore adoptionba0b307
lines 3–48why, one step back34#[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 {}Merge pull request #50 from dtolnay/boxedDavid Tolnaybefore adoption74fbea6
line 49why, one step back49Merge pull request #53 from dtolnay/nostdDavid Tolnaybefore adoption55343b9
line 50why, one step back50#[cfg(feature = "std")]Merge pull request #50 from dtolnay/boxedDavid Tolnaybefore adoption74fbea6
lines 51–53why, one step back51#[repr(transparent)]52pub struct BoxedError(pub Box<dyn StdError + Send + Sync>);53Merge pull request #53 from dtolnay/nostdDavid Tolnaybefore adoption55343b9
line 54why, one step back54#[cfg(feature = "std")]Merge pull request #50 from dtolnay/boxedDavid Tolnaybefore adoption74fbea6
lines 55–60why, one step back55impl Debug for BoxedError {56 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {57 Debug::fmt(&self.0, f)58 }59}60Merge pull request #53 from dtolnay/nostdDavid Tolnaybefore adoption55343b9
line 61why, one step back61#[cfg(feature = "std")]Merge pull request #50 from dtolnay/boxedDavid Tolnaybefore adoption74fbea6
lines 62–67why, one step back62impl Display for BoxedError {63 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {64 Display::fmt(&self.0, f)65 }66}67Merge pull request #53 from dtolnay/nostdDavid Tolnaybefore adoption55343b9
line 68why, one step back68#[cfg(feature = "std")]Merge pull request #50 from dtolnay/boxedDavid Tolnaybefore adoption74fbea6
lines 69–70why, one step back69impl StdError for BoxedError {70 #[cfg(backtrace)]Avoid unused import when building without backtraceDavid Tolnaybefore adoptione7fd273
line 71why, one step back71 fn backtrace(&self) -> Option<&crate::backtrace::Backtrace> {Merge pull request #50 from dtolnay/boxedDavid Tolnaybefore adoption74fbea6
lines 72–78why, one step back72 self.0.backtrace()73 }7475 fn source(&self) -> Option<&(dyn StdError + 'static)> {76 self.0.source()77 }78}