Simplify types for ration impls
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
All checks were successful
timw4mail/rusty-numbers/pipeline/head This commit looks good
This commit is contained in:
parent
3323c2ff23
commit
4f5dcddcc5
@ -99,7 +99,9 @@ pub trait Int:
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A Trait representing unsigned integer primitives
|
/// 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
|
/// Find the greatest common denominator of two numbers
|
||||||
fn gcd(a: Self, b: Self) -> Self;
|
fn gcd(a: Self, b: Self) -> Self;
|
||||||
|
|
||||||
|
@ -144,19 +144,13 @@ impl<T: Unsigned> Frac<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> PartialOrd for Frac<T>
|
impl<T: Unsigned> PartialOrd for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||||
Some(self.cmp(other))
|
Some(self.cmp(other))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Ord for Frac<T>
|
impl<T: Unsigned> Ord for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
fn cmp(&self, other: &Self) -> Ordering {
|
fn cmp(&self, other: &Self) -> Ordering {
|
||||||
if self.sign != other.sign {
|
if self.sign != other.sign {
|
||||||
return if self.sign == Positive {
|
return if self.sign == Positive {
|
||||||
@ -191,10 +185,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Mul for Frac<T>
|
impl<T: Unsigned> Mul for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn mul(self, rhs: Self) -> Self {
|
fn mul(self, rhs: Self) -> Self {
|
||||||
@ -206,19 +197,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> MulAssign for Frac<T>
|
impl<T: Unsigned> MulAssign for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
fn mul_assign(&mut self, rhs: Self) {
|
fn mul_assign(&mut self, rhs: Self) {
|
||||||
*self = *self * rhs
|
*self = *self * rhs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Div for Frac<T>
|
impl<T: Unsigned> Div for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn div(self, rhs: Self) -> Self {
|
fn div(self, rhs: Self) -> Self {
|
||||||
@ -230,19 +215,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> DivAssign for Frac<T>
|
impl<T: Unsigned> DivAssign for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
fn div_assign(&mut self, rhs: Self) {
|
fn div_assign(&mut self, rhs: Self) {
|
||||||
*self = *self / rhs
|
*self = *self / rhs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Add for Frac<T>
|
impl<T: Unsigned> Add for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn add(self, rhs: Self) -> Self::Output {
|
fn add(self, rhs: Self) -> Self::Output {
|
||||||
@ -276,19 +255,13 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> AddAssign for Frac<T>
|
impl<T: Unsigned> AddAssign for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
*self = *self + rhs
|
*self = *self + rhs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Sub for Frac<T>
|
impl<T: Unsigned> Sub for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
type Output = Self;
|
type Output = Self;
|
||||||
|
|
||||||
fn sub(self, rhs: Self) -> Self::Output {
|
fn sub(self, rhs: Self) -> Self::Output {
|
||||||
@ -324,10 +297,7 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> SubAssign for Frac<T>
|
impl<T: Unsigned> SubAssign for Frac<T> {
|
||||||
where
|
|
||||||
T: Unsigned + Add<Output = T> + Sub<Output = T> + Mul<Output = T> + Div<Output = T>,
|
|
||||||
{
|
|
||||||
fn sub_assign(&mut self, rhs: Self) {
|
fn sub_assign(&mut self, rhs: Self) {
|
||||||
*self = *self - rhs
|
*self = *self - rhs
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user