Skip to content

Commit cf83ff8

Browse files
committed
Add requirements of TotalEq and TotalOrd
Clarify that TotalEq needs an underlying equivalence relation and that TotalOrd needs a total ordering and specifically named the required (and sufficient) attributes.
1 parent 667f82a commit cf83ff8

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

src/libstd/cmp.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,18 @@ pub trait Eq {
6262
fn ne(&self, other: &Self) -> bool { !self.eq(other) }
6363
}
6464

65-
/// Trait for equality comparisons where `a == b` and `a != b` are strict inverses.
65+
/**
66+
* Trait for equality comparisons which are [equivalence relations](
67+
* https://en.wikipedia.org/wiki/Equivalence_relation).
68+
*
69+
* This means, that in addition to `a == b` and `a != b` being strict inverses,
70+
* the equality must be (for all `a`, `b` and `c`):
71+
*
72+
* - reflexive: `a == a`;
73+
* - symmetric: `a == b` implies `b == a`; and
74+
* - transitive: `a == b` and `b == c` implies `a == c`.
75+
*/
76+
6677
pub trait TotalEq: Eq {
6778
// FIXME #13101: this method is used solely by #[deriving] to
6879
// assert that every component of a type implements #[deriving]
@@ -111,7 +122,17 @@ pub enum Ordering {
111122
Greater = 1
112123
}
113124

114-
/// Trait for types that form a total order.
125+
/**
126+
* Trait for types that form a [total order](
127+
* https://en.wikipedia.org/wiki/Total_order).
128+
*
129+
* An order is a total order if it is (for all `a`, `b` and `c`):
130+
*
131+
* - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b`
132+
* is true; and
133+
* - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for
134+
* both `==` and `>`.
135+
*/
115136
pub trait TotalOrd: TotalEq + Ord {
116137
/// This method returns an ordering between `self` and `other` values.
117138
///

0 commit comments

Comments
 (0)