Skip to content

Commit 598d7a2

Browse files
committed
replace method with ZERO constant
1 parent ccb607d commit 598d7a2

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

gix-utils/src/btoi.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ pub fn to_unsigned_with_radix<I: MinNumTraits>(bytes: &[u8], radix: u32) -> Resu
118118
return Err(ParseIntegerError { kind: ErrorKind::Empty });
119119
}
120120

121-
let mut result = I::zero();
121+
let mut result = I::ZERO;
122122

123123
for &digit in bytes {
124124
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
236236
return Err(ParseIntegerError { kind: ErrorKind::Empty });
237237
}
238238

239-
let mut result = I::zero();
239+
let mut result = I::ZERO;
240240

241241
for &digit in digits {
242242
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
270270

271271
/// minimal subset of traits used by [`to_signed_with_radix`] and [`to_unsigned_with_radix`]
272272
pub trait MinNumTraits: Sized + Copy {
273+
/// the 0 value for this type
274+
const ZERO: Self;
273275
///
274276
fn from_u32(n: u32) -> Option<Self>;
275277
///
276-
fn zero() -> Self;
277-
///
278278
fn checked_mul(self, v: Self) -> Option<Self>;
279279
///
280280
fn checked_add(self, v: Self) -> Option<Self>;
@@ -285,15 +285,13 @@ pub trait MinNumTraits: Sized + Copy {
285285
macro_rules! min_num_traits {
286286
($t : ty, from_u32 => $from_u32 : expr) => {
287287
impl MinNumTraits for $t {
288+
const ZERO: Self = 0;
289+
288290
fn from_u32(n: u32) -> Option<$t> {
289291
#[allow(clippy::redundant_closure_call)]
290292
$from_u32(n)
291293
}
292294

293-
fn zero() -> Self {
294-
0
295-
}
296-
297295
fn checked_mul(self, v: $t) -> Option<$t> {
298296
<$t>::checked_mul(self, v)
299297
}

0 commit comments

Comments
 (0)