@@ -118,7 +118,7 @@ pub fn to_unsigned_with_radix<I: MinNumTraits>(bytes: &[u8], radix: u32) -> Resu
118
118
return Err ( ParseIntegerError { kind : ErrorKind :: Empty } ) ;
119
119
}
120
120
121
- let mut result = I :: zero ( ) ;
121
+ let mut result = I :: ZERO ;
122
122
123
123
for & digit in bytes {
124
124
let x = match char:: from ( digit) . to_digit ( radix) . and_then ( I :: from_u32) {
@@ -236,7 +236,7 @@ pub fn to_signed_with_radix<I: MinNumTraits>(bytes: &[u8], radix: u32) -> Result
236
236
return Err ( ParseIntegerError { kind : ErrorKind :: Empty } ) ;
237
237
}
238
238
239
- let mut result = I :: zero ( ) ;
239
+ let mut result = I :: ZERO ;
240
240
241
241
for & digit in digits {
242
242
let x = match char:: from ( digit) . to_digit ( radix) . and_then ( I :: from_u32) {
@@ -270,11 +270,11 @@ pub fn to_signed_with_radix<I: MinNumTraits>(bytes: &[u8], radix: u32) -> Result
270
270
271
271
/// minimal subset of traits used by [`to_signed_with_radix`] and [`to_unsigned_with_radix`]
272
272
pub trait MinNumTraits : Sized + Copy {
273
+ /// the 0 value for this type
274
+ const ZERO : Self ;
273
275
///
274
276
fn from_u32 ( n : u32 ) -> Option < Self > ;
275
277
///
276
- fn zero ( ) -> Self ;
277
- ///
278
278
fn checked_mul ( self , v : Self ) -> Option < Self > ;
279
279
///
280
280
fn checked_add ( self , v : Self ) -> Option < Self > ;
@@ -285,15 +285,13 @@ pub trait MinNumTraits: Sized + Copy {
285
285
macro_rules! min_num_traits {
286
286
( $t : ty, from_u32 => $from_u32 : expr) => {
287
287
impl MinNumTraits for $t {
288
+ const ZERO : Self = 0 ;
289
+
288
290
fn from_u32( n: u32 ) -> Option <$t> {
289
291
#[ allow( clippy:: redundant_closure_call) ]
290
292
$from_u32( n)
291
293
}
292
294
293
- fn zero( ) -> Self {
294
- 0
295
- }
296
-
297
295
fn checked_mul( self , v: $t) -> Option <$t> {
298
296
<$t>:: checked_mul( self , v)
299
297
}
0 commit comments