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