@@ -25,28 +25,31 @@ use std::ops::{
25
25
/// as they exist for the unsigned numbers only.
26
26
pub trait Integer :
27
27
Sized
28
- + Add
28
+ + Add < Self , Output = Self >
29
29
+ AddAssign
30
- + Sub
30
+ + Sub < Self , Output = Self >
31
31
+ SubAssign
32
- + Shr
32
+ + Shr < Self , Output = Self >
33
33
+ ShrAssign
34
- + Shl
34
+ + Shl < Self , Output = Self >
35
35
+ ShlAssign
36
- + BitAnd
36
+ + BitAnd < Self , Output = Self >
37
37
+ BitAndAssign
38
- + BitOr
38
+ + BitOr < Self , Output = Self >
39
39
+ BitOrAssign
40
- + BitXor
40
+ + BitXor < Self , Output = Self >
41
41
+ BitXorAssign
42
- + Div
42
+ + Div < Self , Output = Self >
43
43
+ DivAssign
44
- + Mul
44
+ + Mul < Self , Output = Self >
45
45
+ MulAssign
46
46
+ Copy
47
47
{
48
+ /// The smallest value that can be represented by this integer type.
48
49
const MIN : Self ;
50
+ /// The largest value that can be represented by this integer type.
49
51
const MAX : Self ;
52
+ /// The size of this integer type in bits.
50
53
const BITS : u32 ;
51
54
52
55
/// See [`u128::from_str_radix`].
@@ -453,4 +456,14 @@ mod tests {
453
456
10u32 . trailing_ones( )
454
457
) ;
455
458
}
459
+
460
+ fn accepts_any_integer < I : super :: Integer > ( a : I , b : I ) -> u32 {
461
+ ( a + b) . count_ones ( )
462
+ }
463
+
464
+ #[ test]
465
+ fn composite ( ) {
466
+ assert_eq ! ( accepts_any_integer( 0u8 , 0u8 ) , 0 ) ;
467
+ assert_eq ! ( accepts_any_integer( 1i128 , 0i128 ) , 1 ) ;
468
+ }
456
469
}
0 commit comments