← 返回刚才阅读的位置

知识卡片

普通读书笔记卡 · 6075.d.1.d · 生成模型:未记录

轻量入口与可测逻辑

理解等级:中级

把程序入口放在 main.rs,由它调用参数解析和 lib.rs 的 run,最后呈现错误。业务逻辑放到库后,测试可直接调用它,日常失败也更容易定位。参数逻辑很短时可留在入口,长大后可以提取。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第12章 I/O 项目:构建命令行程序(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c12.xhtml`,块 0073) - 结论依据:执行入口和任务逻辑分开后,可直接用函数验证行为。 - 原始内容:This pattern is about separating concerns: main.rs handles running the program and lib.rs handles all the logic of the task at hand. Because you can’t test the main function directly, this structure lets you test all of your program’s logic by moving it into functions in lib.rs. The code that remains in main.rs will be small enough to verify its correctness by reading it.