1use std::cmp::{PartialEq, PartialOrd};
4use std::ops::{Add, BitAnd, Div, Mul, Neg, Rem, Shr, Sub};
5
6pub trait Integer<T>:
7Copy
8+ From<u8>
9+ PartialEq
10+ PartialOrd
11+ Add<Output = T>
12+ BitAnd<Output = T>
13+ Div<Output = T>
14+ Mul<Output = T>
15+ Rem<Output = T>
16+ Shr<Output = T>
17+ Sub<Output = T>
18{
19 const ZERO: T;
20 const ONE: T;
21 const TEN: T;
22}
23
24pub trait Unsigned<T>: Integer<T> {}
25
26pub trait Signed<T>: Integer<T> + Neg<Output = T> {}
27
28macro_rules! integer {
29 ($($t:ty)*) => ($(
30 impl Integer<$t> for $t {
31 const ZERO: $t = 0;
32 const ONE: $t = 1;
33 const TEN: $t = 10;
34 }
35 )*)
36}
37
38macro_rules! empty_trait {
39 ($name:ident for $($t:ty)*) => ($(
40 impl $name<$t> for $t {}
41 )*)
42}
43
44integer!(u8 u16 u32 u64 u128 usize i16 i32 i64 i128);
45empty_trait!(Unsigned for u8 u16 u32 u64 u128 usize);
46empty_trait!(Signed for i16 i32 i64 i128);