知识卡片

普通读书笔记卡 · 6074.d.1.a.3.c.4.e.1.a.1.c.1 · 生成模型:GPT-6

版本号承诺宏兼容性

理解等级:初级

稳定 crate 通过语义化版本告诉调用方升级的兼容范围。兼容的 bug 修复提高补丁版本,向后兼容的新功能提高次版本,破坏已有调用的变化提高主版本。例如从 1.1.0 修补到 1.1.1,增加兼容功能到 1.2.0,而改变已有接口则进入 2.0.0。

宏的接口还体现在接受的语法和展开后调用方所使用的类型与方法。Cargo 的兼容范围可能使项目自动采用同一主版本中的后续版本,因此无标识的破坏性变更会让原来可编译的调用突然失败。

相关卡片 [[生成代码使用完整路径]]、[[发布检查面向实际包]]。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Macros and the outside world 发布前检查与版本承诺 · 查看原书依据

      This means that bug fixes increase the patch version (e.g., 1.1.0 => 1.1.1), functionality that is backward compatible increases the minor (e.g., 1.1.0 => 1.2.0), and backward-incompatible changes increase the major version (e.g., 1.0.0 => 2.0.0). This is especially important in Rust because Cargo allows you to specify dependencies solely by major: trybuild = "1", for example. Introducing a breaking change without bumping the major version might cause projects to suddenly and unexpectedly break.

    参考来源

    - 位置:《Write Powerful Rust Macros》第10章《Macros and the outside world》(book-source:extracted/Write Powerful Rust Macros/_epub-src/OEBPS/Text/chapter-10.xhtml#p108) - 结论依据:原书用三个版本变化和 Cargo 的主版本约束解释为什么稳定版本发布需要兼容性承诺。 - 原始内容:This means that bug fixes increase the patch version (e.g., 1.1.0 => 1.1.1), functionality that is backward compatible increases the minor (e.g., 1.1.0 => 1.2.0), and backward-incompatible changes increase the major version (e.g., 1.0.0 => 2.0.0). This is especially important in Rust because Cargo allows you to specify dependencies solely by major: trybuild = "1", for example. Introducing a breaking change without bumping the major version might cause projects to suddenly and unexpectedly break.