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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
use TokenStream;
use generate;
/// Derive `Display` and `Error` implementations from `#[error(...)]`
/// declarations.
///
/// A format string defines ordinary display behavior.
///
/// ```rust
/// # use fack_macro::Error;
/// #[derive(Error, Debug)]
/// #[error("failed to read {path}")]
/// struct ReadError {
/// path: String,
/// }
/// ```
///
/// `source(field)` selects the ordinary error source.
///
/// ```rust
/// # use fack_macro::Error;
/// #[derive(Error, Debug)]
/// #[error("network request failed")]
/// #[error(source(io))]
/// struct NetworkError {
/// io: std::io::Error,
/// }
/// ```
///
/// `transparent(field)` requires exactly one non-optional field. Display
/// forwards to that field and source chaining forwards through the field's own
/// `Error::source` implementation.
///
/// ```rust
/// # use fack_macro::Error;
/// #[derive(Error, Debug)]
/// #[error(transparent(0))]
/// struct Wrapper(std::io::Error);
/// ```
///
/// `from` requires exactly one field. It generates `From<T>` and selects that
/// field as the ordinary source.
///
/// ```rust
/// # use fack_macro::Error;
/// #[derive(Error, Debug)]
/// #[error("parse failed")]
/// #[error(from)]
/// struct ParseError(std::num::ParseIntError);
/// ```
///
/// `display(path)` selects a custom formatter function.
///
/// ```rust
/// # use fack_macro::Error;
/// fn render(error: &Rendered, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
/// let Rendered { code } = error;
/// write!(f, "rendered {code}")
/// }
///
/// #[derive(Error, Debug)]
/// #[error(display(render))]
/// struct Rendered {
/// code: u8,
/// }
/// ```
///
/// Inline control is optional. Omitting it emits no explicit inline attribute.
/// `inline` and `inline(neutral)` emit ordinary `#[inline]`. The `always` and
/// `never` strategies emit the corresponding Rust attributes.
///
/// ```rust
/// # use fack_macro::Error;
/// #[derive(Error, Debug)]
/// #[error(inline(never))]
/// #[error("rare error")]
/// struct RareError;
/// ```
///
/// Generated paths use `::core` by default. `import(path)` selects a different
/// root.
///
/// ```rust
/// # use fack_macro::Error;
/// #[derive(Error, Debug)]
/// #[error(import(::std))]
/// #[error("standard error")]
/// struct StdError;
/// ```