From 4da1dc74954fafe4d21841892bafc955a37ac805 Mon Sep 17 00:00:00 2001 From: muqiuhan Date: Tue, 27 May 2025 06:06:45 +0000 Subject: deploy: 74a1d57ead41454de540829cd6de5ba1f5702bd6 --- "2023/05/02/Rust-Partial-\350\257\255\344\271\211/index.html" | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to '2023/05/02/Rust-Partial-语义/index.html') diff --git "a/2023/05/02/Rust-Partial-\350\257\255\344\271\211/index.html" "b/2023/05/02/Rust-Partial-\350\257\255\344\271\211/index.html" index a55ca90c..460e970b 100644 --- "a/2023/05/02/Rust-Partial-\350\257\255\344\271\211/index.html" +++ "b/2023/05/02/Rust-Partial-\350\257\255\344\271\211/index.html" @@ -205,10 +205,10 @@

在全部比较可能的场景,我们会使用Ord trait,它要求实现cmp方法,总是返回一个Ordering,表示两个值之间的确切比较关系。Ord是在所有值都能够比较时使用的,例如整数和字符串。

设计用意和解决的问题

Rust 设计 PartialEq 和 PartialOrd trait 主要出于以下几个理由:

PartialEq 和 PartialOrd trait 的设计允许程序员选择精准的相等性和排序语义,同时明确了对于某些类型相等性比较和大小排序并不总是可能的事实。通过引入适度的复杂性,让 Rust 的类型系统更加安全。

-- cgit v1.2.3