Skip to content

Add requirements of TotalEq and TotalOrd #13358

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

Merged
merged 2 commits into from
Apr 7, 2014
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions src/libstd/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,18 @@ pub trait Eq {
fn ne(&self, other: &Self) -> bool { !self.eq(other) }
}

/// Trait for equality comparisons where `a == b` and `a != b` are strict inverses.
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we don't use block comments, use /// on every line.

* Trait for equality comparisons which are [equivalence relations](
* https://en.wikipedia.org/wiki/Equivalence_relation).
*
* This means, that in addition to `a == b` and `a != b` being strict inverses,
* the equality must be (for all `a`, `b` and `c`):
*
* - reflexive: `a == a`;
* - symmetric: `a == b` implies `b == a`; and
* - transitive: `a == b` and `b == c` implies `a == c`.
*/

pub trait TotalEq: Eq {
// FIXME #13101: this method is used solely by #[deriving] to
// assert that every component of a type implements #[deriving]
Expand Down Expand Up @@ -111,7 +122,17 @@ pub enum Ordering {
Greater = 1
}

/// Trait for types that form a total order.
/**
* Trait for types that form a [total order](
* https://en.wikipedia.org/wiki/Total_order).
*
* An order is a total order if it is (for all `a`, `b` and `c`):
*
* - total and antisymmetric: exactly one of `a < b`, `a == b` or `a > b`
* is true; and
* - transitive, `a < b` and `b < c` implies `a < c`. The same must hold for
* both `==` and `>`.
*/
pub trait TotalOrd: TotalEq + Ord {
/// This method returns an ordering between `self` and `other` values.
///
Expand Down