@@ -35,8 +35,10 @@ use self::Ordering::*;
35
35
/// so floating point types implement `PartialEq` but not [`trait@Eq`].
36
36
///
37
37
/// Implementations must ensure that `eq` and `ne` are consistent with each other:
38
- /// `a != b` if and only if `!(a == b)`.
39
- /// This is ensured by the default implementation of `ne`.
38
+ ///
39
+ /// - `a != b` if and only if `!(a == b)`
40
+ /// (ensured by the default implementation).
41
+ ///
40
42
/// If [`PartialOrd`] or [`Ord`] are also implemented for `Self` and `Rhs`, their methods must also
41
43
/// be consistent with `PartialEq` (see the documentation of those traits for the exact
42
44
/// requirememts). It's easy to accidentally make them disagree by deriving some of the traits and
@@ -633,22 +635,25 @@ impl<T: Clone> Clone for Reverse<T> {
633
635
634
636
/// Trait for types that form a [total order](https://en.wikipedia.org/wiki/Total_order).
635
637
///
636
- /// An order is a total order if it is (for all `a`, `b` and `c`):
638
+ /// Implementations must ensure to be consistent with the [`PartialOrd`] implementation, and that
639
+ /// `max`, `min`, and `clamp` are consistent with `cmp`:
637
640
///
638
- /// - total and asymmetric: exactly one of `a < b`, `a == b` or `a > b` is true; and
639
- /// - transitive: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
641
+ /// - `partial_cmp(a, b) == Some(cmp(a, b))`.
642
+ /// - `max(a, b) == max_by(a, b, cmp)` (ensured by the default implementation).
643
+ /// - `min(a, b) == min_by(a, b, cmp)` (ensured by the default implementation).
644
+ /// - For `a.clamp(min, max)`, see the [method docs](#method.clamp)
645
+ /// (ensured by the default implementation).
640
646
///
641
- /// Implementations of [`PartialEq`], [`PartialOrd`], and `Ord` *must* agree with each other (for
642
- /// all `a` and `b`):
647
+ /// It's easy to accidentally make `cmp` and `partial_cmp` disagree by
648
+ /// deriving some of the traits and manually implementing others.
643
649
///
644
- /// - `a.partial_cmp(b) == Some(a.cmp(b))`
645
- /// - `a.cmp(b) == Ordering::Equal` if and only if `a == b`
646
- /// (already follows from the above and the requirements of `PartialOrd`)
650
+ /// ## Corollaries
647
651
///
648
- /// It's easy to accidentally make them disagree by
649
- /// deriving some of the traits and manually implementing others.
652
+ /// From the above and the requirements of `PartialOrd`, it follows that `<` defines a strict total order.
653
+ /// This means that for all `a`, `b` and `c`:
650
654
///
651
- /// Furthermore, the `max`, `min`, and `clamp` methods of this trait must be consistent with `cmp`.
655
+ /// - exactly one of `a < b`, `a == b` or `a > b` is true; and
656
+ /// - `<` is transitive: `a < b` and `b < c` implies `a < c`. The same must hold for both `==` and `>`.
652
657
///
653
658
/// ## Derivable
654
659
///
@@ -839,10 +844,14 @@ impl PartialOrd for Ordering {
839
844
/// the following sense:
840
845
///
841
846
/// - `a == b` if and only if `partial_cmp(a, b) == Some(Equal)`.
842
- /// - `a < b` if and only if `partial_cmp(a, b) == Some(Less)`.
843
- /// - `a > b` if and only if `partial_cmp(a, b) == Some(Greater)`.
844
- /// - `a <= b` if and only if `a < b || a == b`.
845
- /// - `a >= b` if and only if `a > b || a == b`.
847
+ /// - `a < b` if and only if `partial_cmp(a, b) == Some(Less)`
848
+ /// (ensured by the default implementation).
849
+ /// - `a > b` if and only if `partial_cmp(a, b) == Some(Greater)`
850
+ /// (ensured by the default implementation).
851
+ /// - `a <= b` if and only if `a < b || a == b`
852
+ /// (ensured by the default implementation).
853
+ /// - `a >= b` if and only if `a > b || a == b`
854
+ /// (ensured by the default implementation).
846
855
/// - `a != b` if and only if `!(a == b)` (already part of `PartialEq`).
847
856
///
848
857
/// If [`Ord`] is also implemented for `Self` and `Rhs`, it must also be consistent with
0 commit comments