wrapper.rs
This file
Path
src/wrapper.rs
84 lines · 1.9 KiB · Rust
Last changed by
Merge pull request #414 from dtolnay/nightlyDavid Tolnaybefore adoption213a9c2
History of this fileTake it
1use crate::StdError;2use core::fmt::{self, Debug, Display};34#[cfg(any(feature = "std", not(anyhow_no_core_error)))]5use alloc::boxed::Box;67#[cfg(error_generic_member_access)]8use crate::nightly::{self, Request};910#[repr(transparent)]11pub struct MessageError<M>(pub M);1213impl<M> Debug for MessageError<M>14where15 M: Display + Debug,16{17 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {18 Debug::fmt(&self.0, f)19 }20}2122impl<M> Display for MessageError<M>23where24 M: Display + Debug,25{26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {27 Display::fmt(&self.0, f)28 }29}3031impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {}3233#[repr(transparent)]34pub struct DisplayError<M>(pub M);3536impl<M> Debug for DisplayError<M>37where38 M: Display,39{40 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {41 Display::fmt(&self.0, f)42 }43}4445impl<M> Display for DisplayError<M>46where47 M: Display,48{49 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {50 Display::fmt(&self.0, f)51 }52}5354impl<M> StdError for DisplayError<M> where M: Display + 'static {}5556#[cfg(any(feature = "std", not(anyhow_no_core_error)))]57#[repr(transparent)]58pub struct BoxedError(pub Box<dyn StdError + Send + Sync>);5960#[cfg(any(feature = "std", not(anyhow_no_core_error)))]61impl Debug for BoxedError {62 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {63 Debug::fmt(&self.0, f)64 }65}6667#[cfg(any(feature = "std", not(anyhow_no_core_error)))]68impl Display for BoxedError {69 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {70 Display::fmt(&self.0, f)71 }72}7374#[cfg(any(feature = "std", not(anyhow_no_core_error)))]75impl StdError for BoxedError {76 fn source(&self) -> Option<&(dyn StdError + 'static)> {77 self.0.source()78 }7980 #[cfg(error_generic_member_access)]81 fn provide<'a>(&'a self, request: &mut Request<'a>) {82 nightly::provide(&*self.0, request);83 }84}