知识卡片
相等是否自反影响类型契约
PartialEq支持相等比较,Eq进一步承诺每个值都与自身相等。浮点NaN不等于自身,因此普通浮点类型不满足Eq。自定义类型若排除了这类例外,应提供一致的Eq承诺;缓存等非身份字段可能需要手工排除,而非直接逐字段比较。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 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