Simplify types for ration impls
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good

This commit is contained in:
Timothy Warren 2020-02-19 21:23:07 -05:00
parent 3323c2ff23
commit 4f5dcddcc5
3 changed files with 28 additions and 56 deletions

View File

@ -99,7 +99,9 @@ pub trait Int:
}
/// A Trait representing unsigned integer primitives
pub trait Unsigned: Int {
pub trait Unsigned:
Int + Add<Output = Self> + Sub<Output = Self> + Mul<Output = Self> + Div<Output = Self>
{
/// Find the greatest common denominator of two numbers
fn gcd(a: Self, b: Self) -> Self;

View File

@ -144,19 +144,13 @@ impl<T: Unsigned> Frac<T> {
}
}
impl<T> PartialOrd for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> PartialOrd for Frac<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl<T> Ord for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> Ord for Frac<T> {
fn cmp(&self, other: &Self) -> Ordering {
if self.sign != other.sign {
return if self.sign == Positive {
@ -191,10 +185,7 @@ where
}
}
impl<T> Mul for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> Mul for Frac<T> {
type Output = Self;
fn mul(self, rhs: Self) -> Self {
@ -206,19 +197,13 @@ where
}
}
impl<T> MulAssign for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> MulAssign for Frac<T> {
fn mul_assign(&mut self, rhs: Self) {
*self = *self * rhs
}
}
impl<T> Div for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> Div for Frac<T> {
type Output = Self;
fn div(self, rhs: Self) -> Self {
@ -230,19 +215,13 @@ where
}
}
impl<T> DivAssign for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> DivAssign for Frac<T> {
fn div_assign(&mut self, rhs: Self) {
*self = *self / rhs
}
}
impl<T> Add for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> Add for Frac<T> {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
@ -276,19 +255,13 @@ where
}
}
impl<T> AddAssign for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> AddAssign for Frac<T> {
fn add_assign(&mut self, rhs: Self) {
*self = *self + rhs
}
}
impl<T> Sub for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> Sub for Frac<T> {
type Output = Self;
fn sub(self, rhs: Self) -> Self::Output {
@ -324,10 +297,7 @@ where
}
}
impl<T> SubAssign for Frac<T>
where
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
{
impl<T: Unsigned> SubAssign for Frac<T> {
fn sub_assign(&mut self, rhs: Self) {
*self = *self - rhs
}