@@ -274,14 +274,22 @@ pub trait MinNumTraits: Sized + Copy {
274
274
const ZERO : Self ;
275
275
///
276
276
fn from_u32 ( n : u32 ) -> Option < Self > ;
277
- ///
278
- fn checked_mul ( self , v : Self ) -> Option < Self > ;
279
- ///
280
- fn checked_add ( self , v : Self ) -> Option < Self > ;
281
- ///
277
+ /// the checked multiplication operation for this type
278
+ fn checked_mul ( self , rhs : Self ) -> Option < Self > ;
279
+ /// the chekced addition operation for this type
280
+ fn checked_add ( self , rhs : Self ) -> Option < Self > ;
281
+ /// the checked subtraction operation for this type
282
282
fn checked_sub ( self , v : Self ) -> Option < Self > ;
283
283
}
284
284
285
+ macro_rules! impl_checked {
286
+ ( $f: ident) => {
287
+ fn $f( self , rhs: Self ) -> Option <Self > {
288
+ Self :: $f( self , rhs)
289
+ }
290
+ } ;
291
+ }
292
+
285
293
macro_rules! min_num_traits {
286
294
( $t : ty, from_u32 => $from_u32 : expr) => {
287
295
impl MinNumTraits for $t {
@@ -292,17 +300,9 @@ macro_rules! min_num_traits {
292
300
$from_u32( n)
293
301
}
294
302
295
- fn checked_mul( self , v: $t) -> Option <$t> {
296
- <$t>:: checked_mul( self , v)
297
- }
298
-
299
- fn checked_add( self , v: $t) -> Option <$t> {
300
- <$t>:: checked_add( self , v)
301
- }
302
-
303
- fn checked_sub( self , v: $t) -> Option <$t> {
304
- <$t>:: checked_sub( self , v)
305
- }
303
+ impl_checked!( checked_add) ;
304
+ impl_checked!( checked_mul) ;
305
+ impl_checked!( checked_sub) ;
306
306
}
307
307
} ;
308
308
}
0 commit comments