more general PartialEq + PartialOrd
This commit is contained in:
parent
64e44846aa
commit
218a7fbf0f
@ -251,15 +251,18 @@ impl_ratio_assign_operator!(RemAssign,rem_assign);
|
||||
// Only implement PartialEq<Self>
|
||||
// Rust's operators aren't actually that good
|
||||
|
||||
impl<Num,Den,T> PartialEq for Ratio<Num,Den>
|
||||
impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialEq<Ratio<RhsNum,RhsDen>> for Ratio<LhsNum,LhsDen>
|
||||
where
|
||||
Num:Copy,
|
||||
Den:Copy,
|
||||
Num:core::ops::Mul<Den,Output=T>,
|
||||
T:PartialEq,
|
||||
LhsNum:Copy,
|
||||
LhsDen:Copy,
|
||||
RhsNum:Copy,
|
||||
RhsDen:Copy,
|
||||
LhsNum:core::ops::Mul<RhsDen,Output=T>,
|
||||
RhsNum:core::ops::Mul<LhsDen,Output=U>,
|
||||
T:PartialEq<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn eq(&self,&other:&Self)->bool{
|
||||
fn eq(&self,other:&Ratio<RhsNum,RhsDen>)->bool{
|
||||
(self.num*other.den).eq(&(other.num*self.den))
|
||||
}
|
||||
}
|
||||
@ -268,15 +271,18 @@ impl<Num,Den> Eq for Ratio<Num,Den>
|
||||
Ratio<Num,Den>:PartialEq,
|
||||
{}
|
||||
|
||||
impl<Num,Den,T> PartialOrd for Ratio<Num,Den>
|
||||
impl<LhsNum,LhsDen,RhsNum,RhsDen,T,U> PartialOrd<Ratio<RhsNum,RhsDen>> for Ratio<LhsNum,LhsDen>
|
||||
where
|
||||
Num:Copy,
|
||||
Den:Copy,
|
||||
Num:core::ops::Mul<Den,Output=T>,
|
||||
T:PartialOrd,
|
||||
LhsNum:Copy,
|
||||
LhsDen:Copy,
|
||||
RhsNum:Copy,
|
||||
RhsDen:Copy,
|
||||
LhsNum:core::ops::Mul<RhsDen,Output=T>,
|
||||
RhsNum:core::ops::Mul<LhsDen,Output=U>,
|
||||
T:PartialOrd<U>,
|
||||
{
|
||||
#[inline]
|
||||
fn partial_cmp(&self,&other:&Self)->Option<core::cmp::Ordering>{
|
||||
fn partial_cmp(&self,other:&Ratio<RhsNum,RhsDen>)->Option<core::cmp::Ordering>{
|
||||
(self.num*other.den).partial_cmp(&(other.num*self.den))
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user