知识卡片
文档示例随宏一起测试
可分发过程宏的文档可以分为条目级和 crate 级。宏定义上的 /// 描述具体调用,lib.rs 的 //! 描述整个 crate,还可以用 #![doc = include_str!("../README.md")] 将 README 合入 crate 文档,减少两份说明分开更新的成本。
Rust 代码块可以作为 doctest 随 cargo test 运行。例子里要导入宏,并保证示例使用的配置路径在测试环境可找到。按 feature 隐藏的宏默认可能不会出现在文档里,书中示范为文档构建加入 doc 条件,也应对其导入与实现使用相容条件,并检查对应 feature 的 doctest。
相关卡片 [[用特性控制宏的导出]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Macros and the outside world rustdoc 的条目、crate 与样例 · 查看原书依据
Because these tests are run when you do a cargo test, you should make sure they actually work—hence the import and the specific configuration path, since lib.rs is in a different location compared to my usage examples. And note the change I made to cfg. Without it, Rust did not generate documentation for this struct because it was hidden behind a feature. Adding the doc profile is one way to make it visible.