From f6db0ef9464a17fa6e547e755b1b5dfa09af9499 Mon Sep 17 00:00:00 2001 From: Huon Wilson Date: Sun, 23 Mar 2014 22:54:42 +1100 Subject: std: remove the `equals` method from `TotalEq`. `TotalEq` is now just an assertion about the `Eq` impl of a type (i.e. `==` is a total equality if a type implements `TotalEq`) so the extra method is just confusing. Also, a new method magically appeared as a hack to allow deriving to assert that the contents of a struct/enum are also TotalEq, because the deriving infrastructure makes it very hard to do anything but create a trait method. (You didn't hear about this horrible work-around from me :(.) --- src/libnum/bigint.rs | 41 ++++++----------------------------------- src/libnum/rational.rs | 6 +++--- 2 files changed, 9 insertions(+), 38 deletions(-) (limited to 'src/libnum') diff --git a/src/libnum/bigint.rs b/src/libnum/bigint.rs index 5716a1dedf3..89ad2b5d1bc 100644 --- a/src/libnum/bigint.rs +++ b/src/libnum/bigint.rs @@ -92,15 +92,11 @@ pub struct BigUint { impl Eq for BigUint { #[inline] - fn eq(&self, other: &BigUint) -> bool { self.equals(other) } -} - -impl TotalEq for BigUint { - #[inline] - fn equals(&self, other: &BigUint) -> bool { + fn eq(&self, other: &BigUint) -> bool { match self.cmp(other) { Equal => true, _ => false } } } +impl TotalEq for BigUint {} impl Ord for BigUint { #[inline] @@ -852,31 +848,9 @@ fn get_radix_base(radix: uint) -> (uint, uint) { } /// A Sign is a `BigInt`'s composing element. -#[deriving(Eq, Clone, Show)] +#[deriving(Eq, Ord, TotalEq, TotalOrd, Clone, Show)] pub enum Sign { Minus, Zero, Plus } -impl Ord for Sign { - #[inline] - fn lt(&self, other: &Sign) -> bool { - match self.cmp(other) { Less => true, _ => false} - } -} - -impl TotalEq for Sign { - #[inline] - fn equals(&self, other: &Sign) -> bool { *self == *other } -} -impl TotalOrd for Sign { - #[inline] - fn cmp(&self, other: &Sign) -> Ordering { - match (*self, *other) { - (Minus, Minus) | (Zero, Zero) | (Plus, Plus) => Equal, - (Minus, Zero) | (Minus, Plus) | (Zero, Plus) => Less, - _ => Greater - } - } -} - impl Neg for Sign { /// Negate Sign value. #[inline] @@ -898,16 +872,13 @@ pub struct BigInt { impl Eq for BigInt { #[inline] - fn eq(&self, other: &BigInt) -> bool { self.equals(other) } -} - -impl TotalEq for BigInt { - #[inline] - fn equals(&self, other: &BigInt) -> bool { + fn eq(&self, other: &BigInt) -> bool { match self.cmp(other) { Equal => true, _ => false } } } +impl TotalEq for BigInt {} + impl Ord for BigInt { #[inline] fn lt(&self, other: &BigInt) -> bool { diff --git a/src/libnum/rational.rs b/src/libnum/rational.rs index a71674c4122..6fb3d492432 100644 --- a/src/libnum/rational.rs +++ b/src/libnum/rational.rs @@ -147,20 +147,20 @@ macro_rules! cmp_impl { cmp_impl!(impl $imp, $($method -> bool),+) }; // return something other than a Ratio - (impl $imp:ident, $($method:ident -> $res:ty),+) => { + (impl $imp:ident, $($method:ident -> $res:ty),*) => { impl + $imp> $imp for Ratio { $( #[inline] fn $method(&self, other: &Ratio) -> $res { (self.numer * other.denom). $method (&(self.denom*other.numer)) } - )+ + )* } }; } cmp_impl!(impl Eq, eq, ne) -cmp_impl!(impl TotalEq, equals) cmp_impl!(impl Ord, lt, gt, le, ge) +cmp_impl!(impl TotalEq, ) cmp_impl!(impl TotalOrd, cmp -> cmp::Ordering) /* Arithmetic */ -- cgit 1.4.1-3-g733a5