diff --git a/src/identities.rs b/src/identities.rs index 046c28d..ff8bf2e 100644 --- a/src/identities.rs +++ b/src/identities.rs @@ -38,20 +38,19 @@ pub trait ZeroConstant: Zero { const ZERO: Self; } -impl Zero for T { - #[inline(always)] - fn zero() -> T { - Self::ZERO - } - - #[inline(always)] - fn is_zero(&self) -> bool { - self == &Self::ZERO - } -} - macro_rules! zero_impl { ($t:ty, $v:expr) => { + impl Zero for $t { + #[inline] + fn zero() -> $t { + $v + } + #[inline] + fn is_zero(&self) -> bool { + *self == $v + } + } + impl ZeroConstant for $t { const ZERO: Self = $v; } @@ -92,6 +91,13 @@ where } } +impl ZeroConstant for Wrapping +where + Wrapping: Add>, +{ + const ZERO: Self = Self(T::ZERO); +} + /// Defines a multiplicative identity element for `Self`. /// /// # Laws @@ -140,20 +146,19 @@ pub trait OneConstant: One { const ONE: Self; } -impl One for T { - #[inline(always)] - fn one() -> T { - Self::ONE - } - - #[inline(always)] - fn is_one(&self) -> bool { - self == &Self::ONE - } -} - macro_rules! one_impl { ($t:ty, $v:expr) => { + impl One for $t { + #[inline] + fn one() -> $t { + $v + } + #[inline] + fn is_one(&self) -> bool { + *self == $v + } + } + impl OneConstant for $t { const ONE: Self = $v; } @@ -190,6 +195,13 @@ where } } +impl OneConstant for Wrapping +where + Wrapping: Mul>, +{ + const ONE: Self = Self(T::ONE); +} + // Some helper functions provided for backwards compatibility. /// Returns the additive identity, `0`.