forked from open-web3-stack/open-runtime-module-library
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patharithmetic.rs
More file actions
87 lines (85 loc) · 1.79 KB
/
arithmetic.rs
File metadata and controls
87 lines (85 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
pub use num_traits::{
Bounded, CheckedAdd, CheckedDiv, CheckedMul, CheckedShl, CheckedShr, CheckedSub, One, Signed, Zero,
};
use sp_std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Rem, RemAssign, Shl, Shr, Sub, SubAssign};
/// A meta trait for arithmetic.
///
/// Arithmetic types do all the usual stuff you'd expect numbers to do. They are
/// guaranteed to be able to represent at least `u32` values without loss, hence
/// the trait implies `From<u32>` and smaller ints. All other conversions are
/// fallible.
pub trait SimpleArithmetic:
Zero
+ One
+ From<u8>
+ From<u16>
+ From<u32>
+ TryInto<u8>
+ TryInto<u16>
+ TryInto<u32>
+ TryFrom<u64>
+ TryInto<u64>
+ TryFrom<u128>
+ TryInto<u128>
+ Add<Self, Output = Self>
+ AddAssign<Self>
+ Sub<Self, Output = Self>
+ SubAssign<Self>
+ Mul<Self, Output = Self>
+ MulAssign<Self>
+ Div<Self, Output = Self>
+ DivAssign<Self>
+ Rem<Self, Output = Self>
+ RemAssign<Self>
+ Shl<u32, Output = Self>
+ Shr<u32, Output = Self>
+ CheckedShl
+ CheckedShr
+ CheckedAdd
+ CheckedSub
+ CheckedMul
+ CheckedDiv
+ PartialOrd<Self>
+ Ord
+ Bounded
+ Sized
{
}
impl<
T: Zero
+ One
+ From<u8>
+ From<u16>
+ From<u32>
+ TryInto<u8>
+ TryInto<u16>
+ TryInto<u32>
+ TryFrom<u64>
+ TryInto<u64>
+ TryFrom<u128>
+ TryInto<u128>
+ Add<Self, Output = Self>
+ AddAssign<Self>
+ Sub<Self, Output = Self>
+ SubAssign<Self>
+ Mul<Self, Output = Self>
+ MulAssign<Self>
+ Div<Self, Output = Self>
+ DivAssign<Self>
+ Rem<Self, Output = Self>
+ RemAssign<Self>
+ Shl<u32, Output = Self>
+ Shr<u32, Output = Self>
+ CheckedShl
+ CheckedShr
+ CheckedAdd
+ CheckedSub
+ CheckedMul
+ CheckedDiv
+ PartialOrd<Self>
+ Ord
+ Bounded
+ Sized,
> SimpleArithmetic for T
{
}