Skip to content

Commit

Permalink
Add ConstOne and ConstZero implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
saona-raimundo committed Apr 14, 2024
1 parent 9c90d56 commit 60619d3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
10 changes: 9 additions & 1 deletion src/fraction/generic_fraction.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::fraction::Sign;
use crate::{
display, Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Integer, Num,
display, Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, ConstOne, ConstZero, FromPrimitive, Integer, Num,
One, ParseRatioError, Ratio, Signed, ToPrimitive, Zero,
};
#[cfg(feature = "with-bigint")]
Expand Down Expand Up @@ -594,12 +594,20 @@ impl<T: Clone + Integer> Zero for GenericFraction<T> {
}
}

impl<T: ConstOne + ConstZero + Integer + Clone> ConstZero for GenericFraction<T> {
const ZERO: GenericFraction<T> = GenericFraction::Rational(Sign::Plus, Ratio::new_raw(ConstZero::ZERO, ConstOne::ONE));
}

impl<T: Clone + Integer> One for GenericFraction<T> {
fn one() -> Self {
GenericFraction::Rational(Sign::Plus, Ratio::one())
}
}

impl<T: ConstOne + Integer + Clone> ConstOne for GenericFraction<T> {
const ONE: GenericFraction<T> = GenericFraction::Rational(Sign::Plus, Ratio::new_raw(ConstOne::ONE, ConstOne::ONE));
}

impl<T: Clone + Integer> Num for GenericFraction<T> {
type FromStrRadixErr = ParseRatioError;

Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ pub use num::rational::{ParseRatioError, Ratio};

pub use num::{
Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedSub, FromPrimitive, Integer, Num, One,
Signed, ToPrimitive, Zero,
Signed, ToPrimitive, traits::{ConstOne, ConstZero}, Zero,
};

#[cfg(test)]
Expand Down

0 comments on commit 60619d3

Please sign in to comment.