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
use TokenStream;
/// 组件宏,标注一个结构体为组件
///
/// ```rust,ignore
/// #[tx_comp] // 默认 单例,无自定义初始化方法,不是配置组件
/// pub struct DbPool { ... }
///
/// #[tx_comp(scope,init)] init 表示有自定义的初始化方法 只有 scope 表示原型,不是配置组件
/// pub struct XxxServer {
/// db: Arc<DbPool>, // 自动注入
/// #[tx_cst(build_count())] // 自定义值
/// count: u32,
/// }
///
/// fn build_count() -> u32 {
/// 0
/// }
/// #[tx_comp(conf)] //表示是配置组件,自动从配置文件加载配置,配置文件路径为 configs / app.toml
/// pub struct AppConfig {
/// port: u16,
/// addr: String,
/// }
/// 自定义值宏
///
/// 调用自定义方法生成自定义值
/// ```rust,ignore
/// #[tx_comp(scope = Prototype)]
/// pub struct XxxServer {
/// db: <DbPool>, // 自动注入
/// #[tx_cst(build_count())] // 自定义值
/// count: u32,
/// }
///
/// fn build_count() -> u32 {
/// 0
/// }