File tree 1 file changed +36
-24
lines changed
1 file changed +36
-24
lines changed Original file line number Diff line number Diff line change @@ -38,20 +38,19 @@ pub trait ZeroConstant: Zero {
38
38
const ZERO : Self ;
39
39
}
40
40
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
-
53
41
macro_rules! zero_impl {
54
42
( $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
+
55
54
impl ZeroConstant for $t {
56
55
const ZERO : Self = $v;
57
56
}
92
91
}
93
92
}
94
93
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
+
95
101
/// Defines a multiplicative identity element for `Self`.
96
102
///
97
103
/// # Laws
@@ -140,20 +146,19 @@ pub trait OneConstant: One {
140
146
const ONE : Self ;
141
147
}
142
148
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
-
155
149
macro_rules! one_impl {
156
150
( $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
+
157
162
impl OneConstant for $t {
158
163
const ONE : Self = $v;
159
164
}
@@ -190,6 +195,13 @@ where
190
195
}
191
196
}
192
197
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
+
193
205
// Some helper functions provided for backwards compatibility.
194
206
195
207
/// Returns the additive identity, `0`.
You can’t perform that action at this time.
0 commit comments