@@ -35,7 +35,7 @@ use self::Ordering::*;
35
35
///
36
36
/// This trait allows for partial equality, for types that do not have a full
37
37
/// equivalence relation. For example, in floating point numbers `NaN != NaN`,
38
- /// so floating point types implement `PartialEq` but not `Eq`.
38
+ /// so floating point types implement `PartialEq` but not [ `Eq`] .
39
39
///
40
40
/// Formally, the equality must be (for all `a`, `b` and `c`):
41
41
///
@@ -55,12 +55,12 @@ use self::Ordering::*;
55
55
///
56
56
/// ## How can I implement `PartialEq`?
57
57
///
58
- /// PartialEq only requires the `eq` method to be implemented; `ne` is defined
59
- /// in terms of it by default. Any manual implementation of `ne` *must* respect
60
- /// the rule that `eq` is a strict inverse of `ne`; that is, `!(a == b)` if and
58
+ /// ` PartialEq` only requires the [ `eq`] method to be implemented; [ `ne`] is defined
59
+ /// in terms of it by default. Any manual implementation of [ `ne`] *must* respect
60
+ /// the rule that [ `eq`] is a strict inverse of [ `ne`] ; that is, `!(a == b)` if and
61
61
/// only if `a != b`.
62
62
///
63
- /// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with
63
+ /// Implementations of `PartialEq`, [ `PartialOrd`] , and [ `Ord`] *must* agree with
64
64
/// each other. It's easy to accidentally make them disagree by deriving some
65
65
/// of the traits and manually implementing others.
66
66
///
@@ -190,6 +190,9 @@ use self::Ordering::*;
190
190
/// assert_eq!(x == y, false);
191
191
/// assert_eq!(x.eq(&y), false);
192
192
/// ```
193
+ ///
194
+ /// [`eq`]: PartialEq::eq
195
+ /// [`ne`]: PartialEq::ne
193
196
#[ lang = "eq" ]
194
197
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
195
198
#[ doc( alias = "==" ) ]
@@ -233,7 +236,7 @@ pub macro PartialEq($item:item) {
233
236
/// - transitive: `a == b` and `b == c` implies `a == c`.
234
237
///
235
238
/// This property cannot be checked by the compiler, and therefore `Eq` implies
236
- /// `PartialEq`, and has no extra methods.
239
+ /// [ `PartialEq`] , and has no extra methods.
237
240
///
238
241
/// ## Derivable
239
242
///
@@ -370,6 +373,7 @@ impl Ordering {
370
373
/// Chains two orderings.
371
374
///
372
375
/// Returns `self` when it's not `Equal`. Otherwise returns `other`.
376
+ ///
373
377
/// # Examples
374
378
///
375
379
/// ```
@@ -442,10 +446,12 @@ impl Ordering {
442
446
443
447
/// A helper struct for reverse ordering.
444
448
///
445
- /// This struct is a helper to be used with functions like `Vec::sort_by_key` and
449
+ /// This struct is a helper to be used with functions like [ `Vec::sort_by_key`] and
446
450
/// can be used to reverse order a part of a key.
447
451
///
448
- /// Example usage:
452
+ /// [`Vec::sort_by_key`]: ../../std/vec/struct.Vec.html#method.sort_by_key
453
+ ///
454
+ /// # Examples
449
455
///
450
456
/// ```
451
457
/// use std::cmp::Reverse;
@@ -506,12 +512,12 @@ impl<T: Ord> Ord for Reverse<T> {
506
512
///
507
513
/// ## How can I implement `Ord`?
508
514
///
509
- /// `Ord` requires that the type also be `PartialOrd` and `Eq` (which requires `PartialEq`).
515
+ /// `Ord` requires that the type also be [ `PartialOrd`] and [ `Eq`] (which requires [ `PartialEq`] ).
510
516
///
511
- /// Then you must define an implementation for `cmp()` . You may find it useful to use
512
- /// `cmp()` on your type's fields.
517
+ /// Then you must define an implementation for [ `cmp`] . You may find it useful to use
518
+ /// [ `cmp`] on your type's fields.
513
519
///
514
- /// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must*
520
+ /// Implementations of [ `PartialEq`], [ `PartialOrd`] , and `Ord` *must*
515
521
/// agree with each other. That is, `a.cmp(b) == Ordering::Equal` if
516
522
/// and only if `a == b` and `Some(a.cmp(b)) == a.partial_cmp(b)` for
517
523
/// all `a` and `b`. It's easy to accidentally make them disagree by
@@ -548,13 +554,15 @@ impl<T: Ord> Ord for Reverse<T> {
548
554
/// }
549
555
/// }
550
556
/// ```
557
+ ///
558
+ /// [`cmp`]: Ord::cmp
551
559
#[ doc( alias = "<" ) ]
552
560
#[ doc( alias = ">" ) ]
553
561
#[ doc( alias = "<=" ) ]
554
562
#[ doc( alias = ">=" ) ]
555
563
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
556
564
pub trait Ord : Eq + PartialOrd < Self > {
557
- /// This method returns an `Ordering` between `self` and `other`.
565
+ /// This method returns an [ `Ordering`] between `self` and `other`.
558
566
///
559
567
/// By convention, `self.cmp(&other)` returns the ordering matching the expression
560
568
/// `self <operator> other` if true.
@@ -689,20 +697,20 @@ impl PartialOrd for Ordering {
689
697
///
690
698
/// ## How can I implement `PartialOrd`?
691
699
///
692
- /// `PartialOrd` only requires implementation of the `partial_cmp` method, with the others
700
+ /// `PartialOrd` only requires implementation of the [ `partial_cmp`] method, with the others
693
701
/// generated from default implementations.
694
702
///
695
703
/// However it remains possible to implement the others separately for types which do not have a
696
704
/// total order. For example, for floating point numbers, `NaN < 0 == false` and `NaN >= 0 ==
697
705
/// false` (cf. IEEE 754-2008 section 5.11).
698
706
///
699
- /// `PartialOrd` requires your type to be `PartialEq`.
707
+ /// `PartialOrd` requires your type to be [ `PartialEq`] .
700
708
///
701
- /// Implementations of `PartialEq`, `PartialOrd`, and `Ord` *must* agree with each other. It's
709
+ /// Implementations of [ `PartialEq`] , `PartialOrd`, and [ `Ord`] *must* agree with each other. It's
702
710
/// easy to accidentally make them disagree by deriving some of the traits and manually
703
711
/// implementing others.
704
712
///
705
- /// If your type is `Ord`, you can implement `partial_cmp()` by using `cmp()` :
713
+ /// If your type is [ `Ord`] , you can implement [ `partial_cmp`] by using [ `cmp`] :
706
714
///
707
715
/// ```
708
716
/// use std::cmp::Ordering;
@@ -733,7 +741,7 @@ impl PartialOrd for Ordering {
733
741
/// }
734
742
/// ```
735
743
///
736
- /// You may also find it useful to use `partial_cmp()` on your type's fields. Here
744
+ /// You may also find it useful to use [ `partial_cmp`] on your type's fields. Here
737
745
/// is an example of `Person` types who have a floating-point `height` field that
738
746
/// is the only field to be used for sorting:
739
747
///
@@ -768,6 +776,9 @@ impl PartialOrd for Ordering {
768
776
/// assert_eq!(x < y, true);
769
777
/// assert_eq!(x.lt(&y), true);
770
778
/// ```
779
+ ///
780
+ /// [`partial_cmp`]: PartialOrd::partial_cmp
781
+ /// [`cmp`]: Ord::cmp
771
782
#[ lang = "partial_ord" ]
772
783
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
773
784
#[ doc( alias = ">" ) ]
@@ -893,7 +904,7 @@ pub macro PartialOrd($item:item) {
893
904
///
894
905
/// Returns the first argument if the comparison determines them to be equal.
895
906
///
896
- /// Internally uses an alias to `Ord::min`.
907
+ /// Internally uses an alias to [ `Ord::min`] .
897
908
///
898
909
/// # Examples
899
910
///
@@ -956,7 +967,7 @@ pub fn min_by_key<T, F: FnMut(&T) -> K, K: Ord>(v1: T, v2: T, mut f: F) -> T {
956
967
///
957
968
/// Returns the second argument if the comparison determines them to be equal.
958
969
///
959
- /// Internally uses an alias to `Ord::max`.
970
+ /// Internally uses an alias to [ `Ord::max`] .
960
971
///
961
972
/// # Examples
962
973
///
0 commit comments