-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve core::cmp docs #21990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve core::cmp docs #21990
Conversation
r? @aturon (rust_highfive has picked a reviewer for you, use r? to override) |
/// | ||
/// - reflexive: `a == a`; | ||
/// - symmetric: `a == b` implies `b == a`; and | ||
/// - transitive: `a == b` and `b == c` implies `a == c`. | ||
/// | ||
/// This property cannot be checked by the compiler, and so `Eq` implies `PartialEq`, and has no |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think s/and so/therefore/ would sound better here.
7be82c7
to
2307a5c
Compare
Feedback addressed. |
@@ -8,35 +8,33 @@ | |||
// option. This file may not be copied, modified, or distributed | |||
// except according to those terms. | |||
|
|||
//! Defines the `PartialOrd` and `PartialEq` comparison traits. | |||
//! Traits for ordering and comparison. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe s/Traits/Functionality/ since there's things other than traits? (I could just be overly nit-picky)
bc812af
to
c378c07
Compare
/// assert_eq!(Ordering::Greater.reverse(), Ordering::Less); | ||
/// ``` | ||
/// | ||
/// This method is often used to reverse a comparison: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/is often/can be/
c378c07
to
679f6a4
Compare
/// use std::cmp; | ||
/// | ||
/// assert_eq!(Some(1), cmp::partial_min(1, 2)); | ||
/// assert_eq!(Some(2), cmp::partial_min(2, 2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similarly these could demonstrate returning None
, also using NaN.
(Totally minor: Is there a reason that these ones have cmp::partial_min(2, 2)
but the non-partial ones don't?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought I was making them all the same, but it's possible that i just screwed tha tup
956558f
to
7c63cd1
Compare
@@ -302,6 +422,15 @@ pub fn partial_min<T: PartialOrd>(v1: T, v2: T) -> Option<T> { | |||
/// Compare and return the maximum of two values if there is one. | |||
/// | |||
/// Returns the first argument if the comparison determines them to be equal. | |||
/// | |||
/// # Examples |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could have a NaN example too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
truth. fixed!
7c63cd1
to
3d06e91
Compare
/// When comparison is impossible: | ||
/// | ||
/// ``` | ||
/// let result = std::f64::NAN.partial_min(&1.0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and partial_max
should be function calls, not methods.
3d06e91
to
17f9d36
Compare
@huonw should be good to go now |
@bors r+ 17f9 rollup |
Fix up, add examples, make them all the same.
Fix up, add examples, make them all the same.