知识卡片

普通读书笔记卡 · 6076.a.1.a

新增公共成员也可能破坏兼容

理解等级:高级

新增API不总是兼容:公开可构造结构体加字段、可穷尽枚举加变体、trait失去dyn兼容性,都可能让旧代码失败。新方法也可能造成名称冲突,泛化实现可能与下游重叠。判断应看调用者允许做什么,而非只看有没有删除函数。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 4. Dependencies Semver for Crate Authors · 查看原书依据

      Adding new items is usually safe—but may cause clashes if code using the crate already makes use of something that happens to have the same name as the new item. This is a particular danger if the user does a wildcard import from the crate, because all of the crate’s items are then automatically in the user’s main namespace. Item 23 advises against doing thi

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第4章《Semver for Crate Authors》(spine8;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch04.html;u116-ch04-003)。 - 结论依据:原文在“Adding new items”附近的定义、例子或代码支撑本卡核心说明:新增API不总是兼容:公开可构造结构体加字段、可穷尽枚举加变体、trait失去dyn兼容性,都可能让旧代码失败。边界按已读前提解释;示例未执行。 - 原始内容:Adding new items is usually safe—but may cause clashes if code using the crate already makes use of something that happens to have the same name as the new item. This is a particular danger if the user does a wildcard import from the crate, because all of the crate’s items are then automatically in the user’s main namespace. Item 23 advises against doing thi