Skip to content
Myr

wrapper.rs

This file

Path

src/wrapper.rs

81 lines · 1.7 KiB · Rust

Last changed by

Merge pull request #319 from dtolnay/errorprovideDavid Tolnaybefore adoption8cf1d15

History of this file

Take it

1use crate::StdError;2use core::fmt::{self, Debug, Display};34#[cfg(backtrace)]5use std::error::Request;67#[repr(transparent)]8pub struct MessageError<M>(pub M);910impl<M> Debug for MessageError<M>11where12    M: Display + Debug,13{14    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {15        Debug::fmt(&self.0, f)16    }17}1819impl<M> Display for MessageError<M>20where21    M: Display + Debug,22{23    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {24        Display::fmt(&self.0, f)25    }26}2728impl<M> StdError for MessageError<M> where M: Display + Debug + 'static {}2930#[repr(transparent)]31pub struct DisplayError<M>(pub M);3233impl<M> Debug for DisplayError<M>34where35    M: Display,36{37    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {38        Display::fmt(&self.0, f)39    }40}4142impl<M> Display for DisplayError<M>43where44    M: Display,45{46    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {47        Display::fmt(&self.0, f)48    }49}5051impl<M> StdError for DisplayError<M> where M: Display + 'static {}5253#[cfg(feature = "std")]54#[repr(transparent)]55pub struct BoxedError(pub Box<dyn StdError + Send + Sync>);5657#[cfg(feature = "std")]58impl Debug for BoxedError {59    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {60        Debug::fmt(&self.0, f)61    }62}6364#[cfg(feature = "std")]65impl Display for BoxedError {66    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {67        Display::fmt(&self.0, f)68    }69}7071#[cfg(feature = "std")]72impl StdError for BoxedError {73    fn source(&self) -> Option<&(dyn StdError + 'static)> {74        self.0.source()75    }7677    #[cfg(backtrace)]78    fn provide<'a>(&'a self, request: &mut Request<'a>) {79        self.0.provide(request);80    }81}