inherit_config/lib.rs
1#![no_std]
2
3pub use inherit_config_derive::InheritConfig;
4
5pub trait ConfigLayer {
6 /// 对应的全量配置结构体类型
7 type Full: Default;
8
9 /// 继承合并:如果自己为空,则向 parent 借用
10 fn inherit_from(&mut self, parent: &Self);
11
12 /// 差分化简:移除与 parent 相同的字段,以及 parent 未设置时与默认值相同的字段
13 fn simplify_from(&mut self, parent: &Self);
14
15 /// 构建全量结构体:填补所有空白字段为默认值
16 fn build(self) -> Self::Full;
17
18 /// 从全量结构体构造 Partial:所有字段包装为 Some
19 fn from_full(full: Self::Full) -> Self;
20}