@@ -84,31 +84,15 @@ fn unwrap<T>(t: Option<T>) -> T {
84
84
}
85
85
}
86
86
87
- macro_rules! int_impl {
88
- ( $ity: ty, $uty: ty, $bits: expr) => {
89
- impl Int for $uty {
90
- type OtherSign = $ity;
91
- type UnsignedInt = $uty;
92
-
87
+ macro_rules! int_impl_common {
88
+ ( $ty: ty, $bits: expr) => {
93
89
const BITS : u32 = $bits;
94
90
95
91
const ZERO : Self = 0 ;
96
92
const ONE : Self = 1 ;
97
93
98
- fn extract_sign( self ) -> ( bool , $uty) {
99
- ( false , self )
100
- }
101
-
102
- fn unsigned( self ) -> $uty {
103
- self
104
- }
105
-
106
- fn from_unsigned( me: $uty) -> Self {
107
- me
108
- }
109
-
110
94
fn from_bool( b: bool ) -> Self {
111
- b as $uty
95
+ b as $ty
112
96
}
113
97
114
98
fn max_value( ) -> Self {
@@ -146,17 +130,34 @@ macro_rules! int_impl {
146
130
fn leading_zeros( self ) -> u32 {
147
131
<Self >:: leading_zeros( self )
148
132
}
133
+ }
134
+ }
135
+
136
+ macro_rules! int_impl {
137
+ ( $ity: ty, $uty: ty, $bits: expr) => {
138
+ impl Int for $uty {
139
+ type OtherSign = $ity;
140
+ type UnsignedInt = $uty;
141
+
142
+ fn extract_sign( self ) -> ( bool , $uty) {
143
+ ( false , self )
144
+ }
145
+
146
+ fn unsigned( self ) -> $uty {
147
+ self
148
+ }
149
+
150
+ fn from_unsigned( me: $uty) -> Self {
151
+ me
152
+ }
153
+
154
+ int_impl_common!( $uty, $bits) ;
149
155
}
150
156
151
157
impl Int for $ity {
152
158
type OtherSign = $uty;
153
159
type UnsignedInt = $uty;
154
160
155
- const BITS : u32 = $bits;
156
-
157
- const ZERO : Self = 0 ;
158
- const ONE : Self = 1 ;
159
-
160
161
fn extract_sign( self ) -> ( bool , $uty) {
161
162
if self < 0 {
162
163
( true , ( !( self as $uty) ) . wrapping_add( 1 ) )
@@ -173,45 +174,7 @@ macro_rules! int_impl {
173
174
me as $ity
174
175
}
175
176
176
- fn from_bool( b: bool ) -> Self {
177
- b as $ity
178
- }
179
-
180
- fn max_value( ) -> Self {
181
- <Self >:: max_value( )
182
- }
183
-
184
- fn min_value( ) -> Self {
185
- <Self >:: min_value( )
186
- }
187
-
188
- fn wrapping_add( self , other: Self ) -> Self {
189
- <Self >:: wrapping_add( self , other)
190
- }
191
-
192
- fn wrapping_mul( self , other: Self ) -> Self {
193
- <Self >:: wrapping_mul( self , other)
194
- }
195
-
196
- fn wrapping_sub( self , other: Self ) -> Self {
197
- <Self >:: wrapping_sub( self , other)
198
- }
199
-
200
- fn wrapping_shl( self , other: u32 ) -> Self {
201
- <Self >:: wrapping_shl( self , other)
202
- }
203
-
204
- fn aborting_div( self , other: Self ) -> Self {
205
- unwrap( <Self >:: checked_div( self , other) )
206
- }
207
-
208
- fn aborting_rem( self , other: Self ) -> Self {
209
- unwrap( <Self >:: checked_rem( self , other) )
210
- }
211
-
212
- fn leading_zeros( self ) -> u32 {
213
- <Self >:: leading_zeros( self )
214
- }
177
+ int_impl_common!( $ity, $bits) ;
215
178
}
216
179
}
217
180
}
0 commit comments