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
use FromMeta;
use TokenStream;
use Service;
use ;
/// Proc macro attribute to generate service implementation from function declaration. Will
/// generate a struct which implements `micro_tower::Service`.
///
/// # Usage
///
/// A service can be generated by putting `#[micro_tower::codegen::service]` in front of `async`
/// functions.
///
/// ```rust
/// #[micro_tower::codegen::service]
/// async fn service_name(request: ()) -> &'static str {
/// "Hello, World!"
/// }
/// ```
///
/// Errors can be handled using [`Result`].
///
/// ```rust
/// #[micro_tower::codegen::service]
/// async fn service_name(request: ()) -> Result<&'static str, Infallible> {
/// Ok("Hello, World!")
/// }
/// ```
///
/// It is possible to use other services (inner service) in a service by putting an argument with
/// the type of the service.
///
/// ```rust
/// #[micro_tower::codegen::service]
/// async fn service_other(request: (), inner: service_name) -> Result<&'static str, BoxError> {
/// Ok(inner.call(request).await?)
/// }
/// ```
///
/// A service generated with this macro can be build using the builder pattern.
///
/// ```rust
/// let service = service_name::builder().build();
/// ```
///
/// or in case an inner service is used
///
/// ```rust
/// let inner = service_name::builder().build();
/// let service = service_other::builder().inner(inner).build();
/// ```
///
/// the setter for inner services will always be named the same as the service argument.
///
/// # Attributes
///
/// - `crate = "<path>"`: Use to specify a crate path different from `::micro_tower`.
/// - `name = "<name>"`: Change log name of service to `<name>`.
/// - `extend`: Specifies that the service already exists and only `tower::Service` should be
/// implemented.
///
/// # Caveats / Notes
///
/// - non-`async` functions are not supported
/// - for error handling [`std::result::Result`] must be used (and no specialized like
/// [`std::io::Result`])
/// - the generated service is **not** clonable