@@ -171,6 +171,28 @@ macro_rules! impl_fmt_trait {
171
171
} ;
172
172
}
173
173
174
+ trait GetFallback : Sized {
175
+ #[ inline( always) ]
176
+ fn get ( self ) -> Self {
177
+ self
178
+ }
179
+ }
180
+
181
+ impl GetFallback for f32 { }
182
+ impl GetFallback for f64 { }
183
+ impl GetFallback for i8 { }
184
+ impl GetFallback for i16 { }
185
+ impl GetFallback for i32 { }
186
+ impl GetFallback for i64 { }
187
+ impl GetFallback for i128 { }
188
+ impl GetFallback for isize { }
189
+ impl GetFallback for u8 { }
190
+ impl GetFallback for u16 { }
191
+ impl GetFallback for u32 { }
192
+ impl GetFallback for u64 { }
193
+ impl GetFallback for u128 { }
194
+ impl GetFallback for usize { }
195
+
174
196
macro_rules! impl_fmt_traits {
175
197
( $name: ident, $native: ident, "floating point number" ) => {
176
198
impl_fmt_trait!( $name, $native, Display ) ;
@@ -215,8 +237,8 @@ macro_rules! impl_ops_traits {
215
237
impl_ops_traits!( @without_byteorder_swap $name, $native, BitAnd , bitand, BitAndAssign , bitand_assign) ;
216
238
impl_ops_traits!( @without_byteorder_swap $name, $native, BitOr , bitor, BitOrAssign , bitor_assign) ;
217
239
impl_ops_traits!( @without_byteorder_swap $name, $native, BitXor , bitxor, BitXorAssign , bitxor_assign) ;
218
- impl_ops_traits!( @with_byteorder_swap $name, $native, Shl , shl, ShlAssign , shl_assign) ;
219
- impl_ops_traits!( @with_byteorder_swap $name, $native, Shr , shr, ShrAssign , shr_assign) ;
240
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Shl , < { Self } > , shl, ShlAssign , shl_assign) ;
241
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Shr , < { Self } > , shr, ShrAssign , shr_assign) ;
220
242
221
243
impl <O > core:: ops:: Not for $name<O > {
222
244
type Output = $name<O >;
@@ -235,7 +257,7 @@ macro_rules! impl_ops_traits {
235
257
}
236
258
}
237
259
238
- impl <O : ByteOrder > Ord for $name<O > {
260
+ impl <O : ByteOrder > Ord <$native> for $name<O > {
239
261
#[ inline( always) ]
240
262
fn cmp( & self , other: & Self ) -> Ordering {
241
263
self . get( ) . cmp( & other. get( ) )
@@ -255,31 +277,33 @@ macro_rules! impl_ops_traits {
255
277
}
256
278
} ;
257
279
( $name: ident, $native: ident, @all_types) => {
258
- impl_ops_traits!( @with_byteorder_swap $name, $native, Add , add, AddAssign , add_assign) ;
259
- impl_ops_traits!( @with_byteorder_swap $name, $native, Div , div, DivAssign , div_assign) ;
260
- impl_ops_traits!( @with_byteorder_swap $name, $native, Mul , mul, MulAssign , mul_assign) ;
261
- impl_ops_traits!( @with_byteorder_swap $name, $native, Rem , rem, RemAssign , rem_assign) ;
262
- impl_ops_traits!( @with_byteorder_swap $name, $native, Sub , sub, SubAssign , sub_assign) ;
280
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Add , < { Self , $native } > , add, AddAssign , add_assign) ;
281
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Div , < { Self , $native } > , div, DivAssign , div_assign) ;
282
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Mul , < { Self , $native } > , mul, MulAssign , mul_assign) ;
283
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Rem , < { Self , $native } > , rem, RemAssign , rem_assign) ;
284
+ impl_ops_traits!( @with_byteorder_swap $name, $native, Sub , < { Self , $native } > , sub, SubAssign , sub_assign) ;
263
285
} ;
264
- ( @with_byteorder_swap $name: ident, $native: ident, $trait: ident, $method: ident, $trait_assign: ident, $method_assign: ident) => {
265
- impl <O : ByteOrder > core:: ops:: $trait for $name<O > {
266
- type Output = $name<O >;
286
+ ( @with_byteorder_swap $name: ident, $native: ident, $trait: ident, <{ $( $rhs: ident) ,* } >, $method: ident, $trait_assign: ident, $method_assign: ident) => {
287
+ $(
288
+ impl <O : ByteOrder > core:: ops:: $trait<$rhs> for $name<O > {
289
+ type Output = $name<O >;
267
290
268
- #[ inline( always) ]
269
- fn $method( self , rhs: $name<O >) -> $name<O > {
270
- let self_native: $native = self . get( ) ;
271
- let rhs_native: $native = rhs. get( ) ;
272
- let result_native = core:: ops:: $trait:: $method( self_native, rhs_native) ;
273
- $name:: <O >:: new( result_native)
291
+ #[ inline( always) ]
292
+ fn $method( self , rhs: $rhs) -> $name<O > {
293
+ let self_native: $native = self . get( ) ;
294
+ let rhs_native: $native = rhs. get( ) ;
295
+ let result_native = core:: ops:: $trait:: $method( self_native, rhs_native) ;
296
+ $name:: <O >:: new( result_native)
297
+ }
274
298
}
275
- }
276
299
277
- impl <O : ByteOrder > core:: ops:: $trait_assign for $name<O > {
278
- #[ inline( always) ]
279
- fn $method_assign( & mut self , rhs: $name<O >) {
280
- * self = core:: ops:: $trait:: $method( * self , rhs) ;
300
+ impl <O : ByteOrder > core:: ops:: $trait_assign<$rhs> for $name<O > {
301
+ #[ inline( always) ]
302
+ fn $method_assign( & mut self , rhs: $rhs) {
303
+ * self = core:: ops:: $trait:: $method( * self , rhs) ;
304
+ }
281
305
}
282
- }
306
+ ) *
283
307
} ;
284
308
// Implement traits in terms of the same trait on the native type, but
285
309
// without performing a byte order swap. This only works for bitwise
0 commit comments