From 218a7fbf0f0f2d77615f8b88d519e9811cd347d9 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Thu, 3 Oct 2024 12:25:39 -0700 Subject: [PATCH] more general PartialEq + PartialOrd --- ratio_ops/src/ratio.rs | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/ratio_ops/src/ratio.rs b/ratio_ops/src/ratio.rs index b41dc74..a525b71 100644 --- a/ratio_ops/src/ratio.rs +++ b/ratio_ops/src/ratio.rs @@ -251,15 +251,18 @@ impl_ratio_assign_operator!(RemAssign,rem_assign); // Only implement PartialEq // Rust's operators aren't actually that good -impl PartialEq for Ratio +impl PartialEq> for Ratio where - Num:Copy, - Den:Copy, - Num:core::ops::Mul, - T:PartialEq, + LhsNum:Copy, + LhsDen:Copy, + RhsNum:Copy, + RhsDen:Copy, + LhsNum:core::ops::Mul, + RhsNum:core::ops::Mul, + T:PartialEq, { #[inline] - fn eq(&self,&other:&Self)->bool{ + fn eq(&self,other:&Ratio)->bool{ (self.num*other.den).eq(&(other.num*self.den)) } } @@ -268,15 +271,18 @@ impl Eq for Ratio Ratio:PartialEq, {} -impl PartialOrd for Ratio +impl PartialOrd> for Ratio where - Num:Copy, - Den:Copy, - Num:core::ops::Mul, - T:PartialOrd, + LhsNum:Copy, + LhsDen:Copy, + RhsNum:Copy, + RhsDen:Copy, + LhsNum:core::ops::Mul, + RhsNum:core::ops::Mul, + T:PartialOrd, { #[inline] - fn partial_cmp(&self,&other:&Self)->Option{ + fn partial_cmp(&self,other:&Ratio)->Option{ (self.num*other.den).partial_cmp(&(other.num*self.den)) } }