知识卡片
编译示例不等于执行示例主程序
examples展示公共API主线,适合使用Result返回与?传播,让用户复制后仍有合理错误处理。Cargo通常会编译示例检查漂移,但这不等于运行其main;cargo run –example名称才直接执行示例程序,测试harness运行的是测试项。CI需分别声明要构建、测试还是执行。
限定依据:Cargo targets示例规则,2026-10-27查阅。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- Chapter 5. Tooling Examples · 查看原书依据
cargo test --examples), because it can act as a good early warning system for regressions that are likely to affect lots of users. As noted, if your examples demonstrate mainline use of your API, then a failure in the examples implies that something significant is wrong: If it’s a genuine bug, then it’s likely to affect lots of users—the very nature of examp
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第5章《Examples》(spine9;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch05.html;u155-ch05-025)。
- 结论依据:原文在“cargo test --examples”附近的定义、例子或代码支撑本卡核心说明:examples展示公共API主线,适合使用Result返回与?传播,让用户复制后仍有合理错误处理。边界按已读前提解释;示例未执行。
- 原始内容:cargo test --examples), because it can act as a good early warning system for regressions that are likely to affect lots of users. As noted, if your examples demonstrate mainline use of your API, then a failure in the examples implies that something significant is wrong: If it’s a genuine bug, then it’s likely to affect lots of users—the very nature of examp