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
use TokenStream;
use crate;
/// Macro that provides error context on entire function.
/// Supports `async` functions.
///
/// Constraints are `T: Display + Send + Sync + 'static` and `E: WrapErr`.
///
/// # Syntax
/// ```text
/// #[errify( $( $fmt:literal $(, $arg:expr)* ) | $expr:expr )]
/// ```
///
/// # Usage example
///
/// ### Format string with arguments
/// ```ignore
/// use errify::errify;
///
/// #[errify("Custom error context, with argument capturing {arg} = {}", arg)]
/// fn func(arg: i32) -> Result<(), CustomError> {
/// // ...
/// }
/// ```
///
/// ### Expression
/// ```ignore
/// use errify::errify;
///
/// #[errify(String::from("Custom error context"))]
/// fn func(arg: i32) -> Result<(), CustomError> {
/// // ...
/// }
/// ```
/// Macro that provides lazy error context on entire function.
/// Supports `async` functions.
///
/// Constraint is `F: FnOnce() -> impl Display + Send + Sync + 'static` and `E: WrapErr`.
///
/// # Syntax
/// ```text
/// #[errify_with( $closure:expr | $func:ident )]
/// ```
///
/// # Usage example
///
/// ### Closure
/// ```ignore
/// use errify::errify_with;
///
/// #[errify_with(|| "Custom error context from closure")]
/// fn func(arg: i32) -> Result<(), CustomError> {
/// // ...
/// }
/// ```
///
/// ### Function
/// ```ignore
/// use errify::errify_with;
///
/// fn context_provider() -> impl Display { "Context from function" }
///
/// #[errify_with(context_provider)]
/// fn func(arg: i32) -> Result<(), CustomError> {
/// // ...
/// }
/// ```