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