知识卡片
库名前缀组织宏配置
库可以只注册一个具有辨识度的派生辅助属性,再将具体配置写在括号内,例如 #[serde(rename = "name")]。解析时先匹配外层命名,再按子项的路径和是否有值决定如何解释。相比让多个库分别注册 rename、default 等独立名字,这样能明确配置归属,并让未知配置键在统一入口得到诊断。
相关卡片 [[属性形状决定解析方法]]、[[派生辅助属性配置展开]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
- · 真实宏的配置做法
原书出处 · 1 处
- Builder with attributes 真实宏的配置做法 · 查看原书依据
And it has a lot of code to handle the different kinds of metadata. The following is a very partial fragment. It starts by checking whether the attribute is that of serde.
参考来源
- 位置:《Write Powerful Rust Macros》第08章《Builder with attributes》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-8.xhtml#p212)
- 结论依据:清单展示 Serde 只注册一个 serde 辅助属性,再在容器元数据里分派 rename、rename_all、default 并诊断未知键。
- 原始内容:And it has a lot of code to handle the different kinds of metadata. The following is a very partial fragment. It starts by checking whether the attribute is that of serde.