Skip to content

Commit 536dcf2

Browse files
tarciericuviper
authored andcommitted
Remove blanket impls; add impls for Wrapping
1 parent 06c0ee0 commit 536dcf2

File tree

1 file changed

+36
-24
lines changed

1 file changed

+36
-24
lines changed

src/identities.rs

+36-24
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,19 @@ pub trait ZeroConstant: Zero {
3838
const ZERO: Self;
3939
}
4040

41-
impl<T: ZeroConstant + PartialEq> Zero for T {
42-
#[inline(always)]
43-
fn zero() -> T {
44-
Self::ZERO
45-
}
46-
47-
#[inline(always)]
48-
fn is_zero(&self) -> bool {
49-
self == &Self::ZERO
50-
}
51-
}
52-
5341
macro_rules! zero_impl {
5442
($t:ty, $v:expr) => {
43+
impl Zero for $t {
44+
#[inline]
45+
fn zero() -> $t {
46+
$v
47+
}
48+
#[inline]
49+
fn is_zero(&self) -> bool {
50+
*self == $v
51+
}
52+
}
53+
5554
impl ZeroConstant for $t {
5655
const ZERO: Self = $v;
5756
}
@@ -92,6 +91,13 @@ where
9291
}
9392
}
9493

94+
impl<T: ZeroConstant> ZeroConstant for Wrapping<T>
95+
where
96+
Wrapping<T>: Add<Output = Wrapping<T>>,
97+
{
98+
const ZERO: Self = Self(T::ZERO);
99+
}
100+
95101
/// Defines a multiplicative identity element for `Self`.
96102
///
97103
/// # Laws
@@ -140,20 +146,19 @@ pub trait OneConstant: One {
140146
const ONE: Self;
141147
}
142148

143-
impl<T: OneConstant + PartialEq> One for T {
144-
#[inline(always)]
145-
fn one() -> T {
146-
Self::ONE
147-
}
148-
149-
#[inline(always)]
150-
fn is_one(&self) -> bool {
151-
self == &Self::ONE
152-
}
153-
}
154-
155149
macro_rules! one_impl {
156150
($t:ty, $v:expr) => {
151+
impl One for $t {
152+
#[inline]
153+
fn one() -> $t {
154+
$v
155+
}
156+
#[inline]
157+
fn is_one(&self) -> bool {
158+
*self == $v
159+
}
160+
}
161+
157162
impl OneConstant for $t {
158163
const ONE: Self = $v;
159164
}
@@ -190,6 +195,13 @@ where
190195
}
191196
}
192197

198+
impl<T: OneConstant> OneConstant for Wrapping<T>
199+
where
200+
Wrapping<T>: Mul<Output = Wrapping<T>>,
201+
{
202+
const ONE: Self = Self(T::ONE);
203+
}
204+
193205
// Some helper functions provided for backwards compatibility.
194206

195207
/// Returns the additive identity, `0`.

0 commit comments

Comments
 (0)