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
pub unsafe trait Integer: num_traits::PrimInt + crate::scalar::Scalar {
const WIDTH: usize;
const SIGNED: bool;
}
pub trait SignedInteger: Integer {}
pub trait UnsignedInteger: Integer {}
macro_rules! impl_numbers {
(impl UnsignedInteger for $typ:ty;) => {
unsafe impl Integer for $typ {
const WIDTH: usize = core::mem::size_of::<$typ>() * 8;
const SIGNED: bool = false;
}
impl UnsignedInteger for $typ {}
};
(impl SignedInteger for $typ:ty;) => {
unsafe impl Integer for $typ {
const WIDTH: usize = core::mem::size_of::<$typ>() * 8;
const SIGNED: bool = true;
}
impl SignedInteger for $typ {}
};
($(impl $trait:ident for $typ:ty;)+) => {
$(impl_numbers!(impl $trait for $typ;);)+
};
}
impl_numbers! {
impl UnsignedInteger for u8;
impl UnsignedInteger for u16;
impl UnsignedInteger for u32;
impl UnsignedInteger for u64;
impl SignedInteger for i8;
impl SignedInteger for i16;
impl SignedInteger for i32;
impl SignedInteger for i64;
}