知识卡片

普通读书笔记卡 · 6074.d.1.a.3.b

相等是否自反影响类型契约

理解等级:中级

PartialEq支持相等比较,Eq进一步承诺每个值都与自身相等。浮点NaN不等于自身,因此普通浮点类型不满足Eq。自定义类型若排除了这类例外,应提供一致的Eq承诺;缓存等非身份字段可能需要手工排除,而非直接逐字段比较。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 2. Traits PartialEq and Eq · 查看原书依据

      PartialEq and Eq The PartialEq and Eq traits allow you to define equality for user-defined types. These traits have special significance because if they’re present, the compiler will automatically use them for equality (==) checks, similarly to operator== in C++. The default derive implementation does this with a recursive field-by-field comparison. The Eq v

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第2章《PartialEq and Eq》(spine6;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch02.html;u060-ch02-006)。 - 结论依据:原文在“PartialEq and Eq”附近的定义、例子或代码支撑本卡核心说明:PartialEq支持相等比较,Eq进一步承诺每个值都与自身相等。边界按已读前提解释;示例未执行。 - 原始内容:PartialEq and Eq The PartialEq and Eq traits allow you to define equality for user-defined types. These traits have special significance because if they’re present, the compiler will automatically use them for equality (==) checks, similarly to operator== in C++. The default derive implementation does this with a recursive field-by-field comparison. The Eq v