scanlex/
int.rs

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
pub trait Int {
    type Type;
    fn min_value() -> i64;
    fn max_value() -> i64;
    fn name() -> &'static str;
    fn cast(n: i64) -> Self::Type;
}

macro_rules! impl_int {
    ($t:ident) => {
        impl Int for $t {
            type Type = $t;

            fn min_value() -> i64 {
                $t::min_value() as i64
            }

            fn max_value() -> i64 {
                $t::max_value() as i64
            }

            fn name() -> &'static str {
                stringify!($t)
            }

            fn cast(n: i64) -> Self::Type {
                n as Self::Type
            }
        }
    }

}
impl_int!(i8);
impl_int!(i16);
impl_int!(i32);
impl_int!(i64);

impl_int!(u8);
impl_int!(u16);
impl_int!(u32);
impl_int!(u64);