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
//! Unofficial extension macros for the [Salvo web framework](https://github.com/salvo-rs/salvo).
use TokenStream;
use ;
/// `#[module]` is an attribute macro used to batch convert methods in an `impl` block into [`Salvo`'s `Handler`](https://github.com/salvo-rs/salvo).
///
/// ## Example
/// ```
/// use salvo::oapi::extract::*;
/// use salvo::prelude::*;
/// use salvo_macro_ext::module;
///
/// #[derive(Clone)]
/// pub struct Service {
/// state: i64,
/// }
///
/// #[module]
/// impl Service {
/// fn new(state: i64) -> Self {
/// Self { state }
/// }
/// /// doc line 1
/// /// doc line 2
/// #[salvo_macro_ext::module(handler)]
/// fn add1(&self, left: QueryParam<i64, true>, right: QueryParam<i64, true>) -> String {
/// (self.state + *left + *right).to_string()
/// }
/// /// doc line 3
/// /// doc line 4
/// #[module(handler)]
/// pub(crate) fn add2(
/// self: ::std::sync::Arc<Self>,
/// left: QueryParam<i64, true>,
/// right: QueryParam<i64, true>,
/// ) -> String {
/// (self.state + *left + *right).to_string()
/// }
/// /// doc line 5
/// /// doc line 6
/// #[module(handler)]
/// pub fn add3(left: QueryParam<i64, true>, right: QueryParam<i64, true>) -> String {
/// (*left + *right).to_string()
/// }
/// }
/// ```
/// Sure, you can also replace `#[module(handler)]` with `#[module(endpoint(...))]`.
///
/// NOTE: If the receiver of a method is `&self`, you need to implement the `Clone` trait for the type.