@@ -23,8 +23,28 @@ pub use uint;
23
23
#[ macro_export]
24
24
macro_rules! impl_uint_num_traits {
25
25
( $name: ident, $len: expr) => {
26
+ impl $crate:: num_traits:: bounds:: Bounded for $name {
27
+ #[ inline]
28
+ fn min_value( ) -> Self {
29
+ Self :: zero( )
30
+ }
31
+
32
+ #[ inline]
33
+ fn max_value( ) -> Self {
34
+ Self :: max_value( )
35
+ }
36
+ }
37
+
26
38
impl $crate:: num_traits:: sign:: Unsigned for $name { }
27
39
40
+ impl $crate:: num_traits:: identities:: ConstZero for $name {
41
+ const ZERO : Self = Self :: zero( ) ;
42
+ }
43
+
44
+ impl $crate:: num_traits:: identities:: ConstOne for $name {
45
+ const ONE : Self = Self :: one( ) ;
46
+ }
47
+
28
48
impl $crate:: num_traits:: identities:: Zero for $name {
29
49
#[ inline]
30
50
fn zero( ) -> Self {
@@ -58,6 +78,30 @@ macro_rules! impl_uint_num_traits {
58
78
}
59
79
}
60
80
81
+ impl $crate:: num_traits:: ops:: bytes:: FromBytes for $name {
82
+ type Bytes = [ u8 ; $len * 8 ] ;
83
+
84
+ fn from_be_bytes( bytes: & Self :: Bytes ) -> Self {
85
+ Self :: from_big_endian( & bytes[ ..] )
86
+ }
87
+
88
+ fn from_le_bytes( bytes: & Self :: Bytes ) -> Self {
89
+ Self :: from_little_endian( & bytes[ ..] )
90
+ }
91
+ }
92
+
93
+ impl $crate:: num_traits:: ops:: bytes:: ToBytes for $name {
94
+ type Bytes = [ u8 ; $len * 8 ] ;
95
+
96
+ fn to_be_bytes( & self ) -> Self :: Bytes {
97
+ self . to_big_endian( )
98
+ }
99
+
100
+ fn to_le_bytes( & self ) -> Self :: Bytes {
101
+ self . to_little_endian( )
102
+ }
103
+ }
104
+
61
105
impl $crate:: num_traits:: ops:: checked:: CheckedAdd for $name {
62
106
#[ inline]
63
107
fn checked_add( & self , v: & Self ) -> Option <Self > {
@@ -85,5 +129,60 @@ macro_rules! impl_uint_num_traits {
85
129
$name:: checked_mul( * self , * v)
86
130
}
87
131
}
132
+
133
+ impl $crate:: num_traits:: ops:: checked:: CheckedNeg for $name {
134
+ #[ inline]
135
+ fn checked_neg( & self ) -> Option <Self > {
136
+ Self :: checked_neg( * self )
137
+ }
138
+ }
139
+
140
+ impl $crate:: num_traits:: ops:: checked:: CheckedRem for $name {
141
+ #[ inline]
142
+ fn checked_rem( & self , v: & Self ) -> Option <Self > {
143
+ Self :: checked_rem( * self , * v)
144
+ }
145
+ }
146
+
147
+ impl $crate:: num_traits:: ops:: saturating:: Saturating for $name {
148
+ #[ inline]
149
+ fn saturating_add( self , v: Self ) -> Self {
150
+ Self :: saturating_add( self , v)
151
+ }
152
+
153
+ #[ inline]
154
+ fn saturating_sub( self , v: Self ) -> Self {
155
+ Self :: saturating_sub( self , v)
156
+ }
157
+ }
158
+
159
+ impl $crate:: num_traits:: ops:: saturating:: SaturatingAdd for $name {
160
+ #[ inline]
161
+ fn saturating_add( & self , v: & Self ) -> Self {
162
+ Self :: saturating_add( * self , * v)
163
+ }
164
+ }
165
+
166
+ impl $crate:: num_traits:: ops:: saturating:: SaturatingMul for $name {
167
+ #[ inline]
168
+ fn saturating_mul( & self , v: & Self ) -> Self {
169
+ Self :: saturating_mul( * self , * v)
170
+ }
171
+ }
172
+
173
+ impl $crate:: num_traits:: ops:: saturating:: SaturatingSub for $name {
174
+ #[ inline]
175
+ fn saturating_sub( & self , v: & Self ) -> Self {
176
+ Self :: saturating_sub( * self , * v)
177
+ }
178
+ }
179
+
180
+ impl $crate:: num_traits:: pow:: Pow <Self > for $name {
181
+ type Output = Self ;
182
+
183
+ fn pow( self , rhs: Self ) -> Self {
184
+ Self :: pow( self , rhs)
185
+ }
186
+ }
88
187
} ;
89
188
}
0 commit comments