@@ -229,44 +229,35 @@ pub enum FullInt {
229
229
U ( u128 ) ,
230
230
}
231
231
232
- impl FullInt {
233
- #[ allow( clippy:: cast_sign_loss) ]
234
- #[ must_use]
235
- fn cmp_s_u ( s : i128 , u : u128 ) -> Ordering {
236
- if s < 0 {
237
- Ordering :: Less
238
- } else if u > ( i128:: MAX as u128 ) {
239
- Ordering :: Greater
240
- } else {
241
- ( s as u128 ) . cmp ( & u)
242
- }
243
- }
244
- }
245
-
246
232
impl PartialEq for FullInt {
247
233
#[ must_use]
248
234
fn eq ( & self , other : & Self ) -> bool {
249
- self . partial_cmp ( other) . expect ( "`partial_cmp` only returns `Some(_)`" ) == Ordering :: Equal
235
+ self . cmp ( other) == Ordering :: Equal
250
236
}
251
237
}
252
238
253
239
impl PartialOrd for FullInt {
254
240
#[ must_use]
255
241
fn partial_cmp ( & self , other : & Self ) -> Option < Ordering > {
256
- Some ( match ( self , other) {
257
- ( & Self :: S ( s) , & Self :: S ( o) ) => s. cmp ( & o) ,
258
- ( & Self :: U ( s) , & Self :: U ( o) ) => s. cmp ( & o) ,
259
- ( & Self :: S ( s) , & Self :: U ( o) ) => Self :: cmp_s_u ( s, o) ,
260
- ( & Self :: U ( s) , & Self :: S ( o) ) => Self :: cmp_s_u ( o, s) . reverse ( ) ,
261
- } )
242
+ Some ( self . cmp ( other) )
262
243
}
263
244
}
264
245
265
246
impl Ord for FullInt {
266
247
#[ must_use]
267
248
fn cmp ( & self , other : & Self ) -> Ordering {
268
- self . partial_cmp ( other)
269
- . expect ( "`partial_cmp` for FullInt can never return `None`" )
249
+ use FullInt :: { S , U } ;
250
+
251
+ fn cmp_s_u ( s : i128 , u : u128 ) -> Ordering {
252
+ u128:: try_from ( s) . map_or ( Ordering :: Less , |x| x. cmp ( & u) )
253
+ }
254
+
255
+ match ( * self , * other) {
256
+ ( S ( s) , S ( o) ) => s. cmp ( & o) ,
257
+ ( U ( s) , U ( o) ) => s. cmp ( & o) ,
258
+ ( S ( s) , U ( o) ) => cmp_s_u ( s, o) ,
259
+ ( U ( s) , S ( o) ) => cmp_s_u ( o, s) . reverse ( ) ,
260
+ }
270
261
}
271
262
}
272
263
0 commit comments