Skip to content

Commit 5a013e0

Browse files
authored
add Semigroup/Monoid impls for unsigned ints (#368)
1 parent 8123b20 commit 5a013e0

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/difference.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,40 @@ macro_rules! builtin_implementation {
7272
#[inline] fn zero() -> Self { 0 }
7373
}
7474

75-
impl Abelian for $t {
76-
#[inline] fn negate(self) -> Self { -self }
77-
}
78-
7975
impl Multiply<Self> for $t {
8076
type Output = Self;
8177
fn multiply(self, rhs: &Self) -> Self { self * rhs}
8278
}
8379
};
8480
}
8581

82+
macro_rules! builtin_abelian_implementation {
83+
($t:ty) => {
84+
impl Abelian for $t {
85+
#[inline] fn negate(self) -> Self { -self }
86+
}
87+
};
88+
}
89+
8690
builtin_implementation!(i8);
8791
builtin_implementation!(i16);
8892
builtin_implementation!(i32);
8993
builtin_implementation!(i64);
9094
builtin_implementation!(i128);
9195
builtin_implementation!(isize);
96+
builtin_implementation!(u8);
97+
builtin_implementation!(u16);
98+
builtin_implementation!(u32);
99+
builtin_implementation!(u64);
100+
builtin_implementation!(u128);
101+
builtin_implementation!(usize);
102+
103+
builtin_abelian_implementation!(i8);
104+
builtin_abelian_implementation!(i16);
105+
builtin_abelian_implementation!(i32);
106+
builtin_abelian_implementation!(i64);
107+
builtin_abelian_implementation!(i128);
108+
builtin_abelian_implementation!(isize);
92109

93110
/// Implementations for wrapping signed integers, which have a different zero.
94111
macro_rules! wrapping_implementation {

0 commit comments

Comments
 (0)