1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
extern crate proc_macro;
use TokenStream;
use ;
pub
pub use *;
use impl_error_enum;
use impl_error_struct;
/// The implementation of trait 'Error' (writed for crate [add_macro](https://docs.rs/add_macro))
///
/// # Examples:
/// ```
/// use add_macro_impl_error::Error;
///
/// #[derive(Debug, Error)]
/// enum CustomError {
/// Io(std::io::Error),
/// Wrong,
/// }
///
/// impl std::fmt::Display for CustomError {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// match &self {
/// Self::Io(e) => write!(f, "{e}"),
/// Self::Wrong => write!(f, "Something went wrong.. =/"),
/// }
/// }
/// }
///
/// #[derive(Debug, Error)]
/// pub struct Error {
/// source: CustomError,
/// }
///
/// impl std::fmt::Display for Error {
/// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// write!(f, "{}", &self.source)
/// }
/// }
///
/// fn main() {
/// let err = CustomError::Wrong;
/// assert_eq!(format!("{err}"), "Something went wrong.. =/");
///
/// let err = Error { source: CustomError::Wrong };
/// assert_eq!(format!("{err}"), "Something went wrong.. =/");
/// }
/// ```