知识卡片
偏序允许不可比较
PartialOrd允许某些值之间没有顺序,例如两个互不包含的集合;Ord要求任意值可比较,并与Eq一致。比较结果都为假不一定相等,NaN就是提醒。业务若需要全序,应明确选择可覆盖所有值的规则,而不是将不可比较默认为相等。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
- · 偏序允许不可比较
原书出处 · 1 处
- Chapter 2. Traits PartialOrd and Ord · 查看原书依据
PartialOrd and Ord The ordering traits PartialOrd and Ord allow comparisons between two items of a type, returning Less, Greater, or Equal. The traits require equivalent equality traits to be implemented (PartialOrd requires PartialEq; Ord requires Eq), and the two have to agree with each other (watch out for this with manual implementations in particular).
参考来源
- 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第2章《PartialOrd and Ord》(spine6;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch02.html;u061-ch02-007)。
- 结论依据:原文在“PartialOrd and Ord”附近的定义、例子或代码支撑本卡核心说明:PartialOrd允许某些值之间没有顺序,例如两个互不包含的集合;Ord要求任意值可比较,并与Eq一致。边界按已读前提解释;示例未执行。
- 原始内容:PartialOrd and Ord The ordering traits PartialOrd and Ord allow comparisons between two items of a type, returning Less, Greater, or Equal. The traits require equivalent equality traits to be implemented (PartialOrd requires PartialEq; Ord requires Eq), and the two have to agree with each other (watch out for this with manual implementations in particular).