Skip to content

Commit 91b1855

Browse files
committed
cleanup checked method impls with macro
1 parent 598d7a2 commit 91b1855

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

gix-utils/src/btoi.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -274,14 +274,22 @@ pub trait MinNumTraits: Sized + Copy {
274274
const ZERO: Self;
275275
///
276276
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
282282
fn checked_sub(self, v: Self) -> Option<Self>;
283283
}
284284

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+
285293
macro_rules! min_num_traits {
286294
($t : ty, from_u32 => $from_u32 : expr) => {
287295
impl MinNumTraits for $t {
@@ -292,17 +300,9 @@ macro_rules! min_num_traits {
292300
$from_u32(n)
293301
}
294302

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);
306306
}
307307
};
308308
}

0 commit comments

Comments
 (0)