@@ -661,20 +661,37 @@ impl<T: Clone> Clone for Reverse<T> {
661
661
///
662
662
/// ## Derivable
663
663
///
664
- /// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
665
- /// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering based on the top-to-bottom declaration order of the struct's members.
666
- /// When `derive`d on enums, variants are ordered by their top-to-bottom discriminant order.
667
- /// This means variants at the top are less than variants at the bottom.
668
- /// Here's an example:
664
+ /// This trait can be used with `#[derive]`.
665
+ ///
666
+ /// When `derive`d on structs, it will produce a
667
+ /// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering
668
+ /// based on the top-to-bottom declaration order of the struct's members.
669
+ ///
670
+ /// When `derive`d on enums, variants are ordered by their discriminants.
671
+ /// By default, the discriminant is smallest for variants at the top, and
672
+ /// largest for variants at the bottom. Here's an example:
669
673
///
670
674
/// ```
671
- /// #[derive(PartialEq, PartialOrd)]
672
- /// enum Size {
673
- /// Small ,
674
- /// Large ,
675
+ /// #[derive(PartialEq, Eq, PartialOrd, Ord )]
676
+ /// enum E {
677
+ /// Top ,
678
+ /// Bottom ,
675
679
/// }
676
680
///
677
- /// assert!(Size::Small < Size::Large);
681
+ /// assert!(E::Top < E::Bottom);
682
+ /// ```
683
+ ///
684
+ /// However, manually setting the discriminants can override this default
685
+ /// behavior:
686
+ ///
687
+ /// ```
688
+ /// #[derive(PartialEq, Eq, PartialOrd, Ord)]
689
+ /// enum E {
690
+ /// Top = 2,
691
+ /// Bottom = 1,
692
+ /// }
693
+ ///
694
+ /// assert!(E::Bottom < E::Top);
678
695
/// ```
679
696
///
680
697
/// ## Lexicographical comparison
@@ -895,9 +912,38 @@ impl PartialOrd for Ordering {
895
912
///
896
913
/// ## Derivable
897
914
///
898
- /// This trait can be used with `#[derive]`. When `derive`d on structs, it will produce a
899
- /// lexicographic ordering based on the top-to-bottom declaration order of the struct's members.
900
- /// When `derive`d on enums, variants are ordered by their top-to-bottom discriminant order.
915
+ /// This trait can be used with `#[derive]`.
916
+ ///
917
+ /// When `derive`d on structs, it will produce a
918
+ /// [lexicographic](https://en.wikipedia.org/wiki/Lexicographic_order) ordering
919
+ /// based on the top-to-bottom declaration order of the struct's members.
920
+ ///
921
+ /// When `derive`d on enums, variants are ordered by their discriminants.
922
+ /// By default, the discriminant is smallest for variants at the top, and
923
+ /// largest for variants at the bottom. Here's an example:
924
+ ///
925
+ /// ```
926
+ /// #[derive(PartialEq, PartialOrd)]
927
+ /// enum E {
928
+ /// Top,
929
+ /// Bottom,
930
+ /// }
931
+ ///
932
+ /// assert!(E::Top < E::Bottom);
933
+ /// ```
934
+ ///
935
+ /// However, manually setting the discriminants can override this default
936
+ /// behavior:
937
+ ///
938
+ /// ```
939
+ /// #[derive(PartialEq, PartialOrd)]
940
+ /// enum E {
941
+ /// Top = 2,
942
+ /// Bottom = 1,
943
+ /// }
944
+ ///
945
+ /// assert!(E::Bottom < E::Top);
946
+ /// ```
901
947
///
902
948
/// ## How can I implement `PartialOrd`?
903
949
///
@@ -970,8 +1016,8 @@ impl PartialOrd for Ordering {
970
1016
/// # Examples
971
1017
///
972
1018
/// ```
973
- /// let x : u32 = 0;
974
- /// let y : u32 = 1;
1019
+ /// let x: u32 = 0;
1020
+ /// let y: u32 = 1;
975
1021
///
976
1022
/// assert_eq!(x < y, true);
977
1023
/// assert_eq!(x.lt(&y), true);
0 commit comments