tuwunel_core/utils/math/
tried.rs1use num_traits::ops::checked::{CheckedAdd, CheckedDiv, CheckedMul, CheckedRem, CheckedSub};
2
3use crate::{Result, checked};
4
5pub trait Tried {
6 #[inline]
7 fn try_add(self, rhs: Self) -> Result<Self>
8 where
9 Self: CheckedAdd + Sized,
10 {
11 checked!(self + rhs)
12 }
13
14 #[inline]
15 fn try_sub(self, rhs: Self) -> Result<Self>
16 where
17 Self: CheckedSub + Sized,
18 {
19 checked!(self - rhs)
20 }
21
22 #[inline]
23 fn try_mul(self, rhs: Self) -> Result<Self>
24 where
25 Self: CheckedMul + Sized,
26 {
27 checked!(self * rhs)
28 }
29
30 #[inline]
31 fn try_div(self, rhs: Self) -> Result<Self>
32 where
33 Self: CheckedDiv + Sized,
34 {
35 checked!(self / rhs)
36 }
37
38 #[inline]
39 fn try_rem(self, rhs: Self) -> Result<Self>
40 where
41 Self: CheckedRem + Sized,
42 {
43 checked!(self % rhs)
44 }
45}
46
47impl<T> Tried for T {}