core: Inherit the cmp module

This removes the TotalOrd and TotalEq implementation macros, they will be added
later to the numeric modules (where the other comparison implementations live).
This commit is contained in:
Alex Crichton 2014-04-30 21:55:14 -07:00
parent b024ba544c
commit 5592a8f5db
4 changed files with 15 additions and 57 deletions

View File

@ -81,32 +81,8 @@ pub trait TotalEq: Eq {
fn assert_receiver_is_total_eq(&self) {}
}
/// A macro which defines an implementation of TotalEq for a given type.
macro_rules! totaleq_impl(
($t:ty) => {
impl TotalEq for $t {}
}
)
totaleq_impl!(bool)
totaleq_impl!(u8)
totaleq_impl!(u16)
totaleq_impl!(u32)
totaleq_impl!(u64)
totaleq_impl!(i8)
totaleq_impl!(i16)
totaleq_impl!(i32)
totaleq_impl!(i64)
totaleq_impl!(int)
totaleq_impl!(uint)
totaleq_impl!(char)
/// An ordering is, e.g, a result of a comparison between two values.
#[deriving(Clone, Eq, Show)]
#[deriving(Clone, Eq)]
pub enum Ordering {
/// An ordering where a compared value is less [than another].
Less = -1,
@ -140,6 +116,7 @@ pub trait TotalOrd: TotalEq + Ord {
}
impl TotalEq for Ordering {}
impl TotalOrd for Ordering {
#[inline]
fn cmp(&self, other: &Ordering) -> Ordering {
@ -152,35 +129,6 @@ impl Ord for Ordering {
fn lt(&self, other: &Ordering) -> bool { (*self as int) < (*other as int) }
}
/// A macro which defines an implementation of TotalOrd for a given type.
macro_rules! totalord_impl(
($t:ty) => {
impl TotalOrd for $t {
#[inline]
fn cmp(&self, other: &$t) -> Ordering {
if *self < *other { Less }
else if *self > *other { Greater }
else { Equal }
}
}
}
)
totalord_impl!(u8)
totalord_impl!(u16)
totalord_impl!(u32)
totalord_impl!(u64)
totalord_impl!(i8)
totalord_impl!(i16)
totalord_impl!(i32)
totalord_impl!(i64)
totalord_impl!(int)
totalord_impl!(uint)
totalord_impl!(char)
/// Combine orderings, lexically.
///
/// For example for a type `(int, int)`, two comparisons could be done.

View File

@ -30,6 +30,7 @@ pub mod ptr;
/* Core language traits */
pub mod cmp;
pub mod kinds;
pub mod ops;
pub mod ty;

View File

@ -486,6 +486,7 @@ will look like `"\\{"`.
use any;
use cast;
use char::Char;
use cmp;
use container::Container;
use io::MemWriter;
use io;
@ -1315,5 +1316,15 @@ impl<T: Show> Show for iter::MinMaxResult<T> {
}
}
impl Show for cmp::Ordering {
fn fmt(&self, f: &mut Formatter) -> Result {
match *self {
cmp::Less => write!(f.buf, "Less"),
cmp::Greater => write!(f.buf, "Greater"),
cmp::Equal => write!(f.buf, "Equal"),
}
}
}
// If you expected tests to be here, look instead at the run-pass/ifmt.rs test,
// it's a lot easier than creating all of the rt::Piece structures here.

View File

@ -135,6 +135,7 @@ extern crate core;
#[cfg(not(test))] pub use kinds = core::kinds;
#[cfg(not(test))] pub use ops = core::ops;
#[cfg(not(test))] pub use cmp = core::cmp;
#[cfg(not(test))] pub use ty = core::ty;
pub use core::any;
@ -207,13 +208,10 @@ mod reference;
pub mod rc;
pub mod gc;
/* Core language traits */
#[cfg(not(test))] pub mod cmp;
#[cfg(not(test))] pub mod owned;
/* Common traits */
pub mod from_str;