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
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum IntegralType {
    Int,
    Long,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FloatingType {
    Double,
    Float,
}

#[derive(Debug, Clone, Copy)]
pub struct Integral {
    pub value: i64,
    pub ty: IntegralType,
}

#[derive(Debug, Clone, Copy)]
pub struct Floating {
    pub value: f64,
    pub ty: FloatingType,
}

macro_rules! from_num {
    ($b: ty > $a: ty, $( $x:ty => $y: expr ),* ) => {
        $(
            impl From<$x> for $b {
              fn from(value: $x) -> Self {
                Self {
                  value: value as $a,
                  ty: $y
                }
              }
            }
        )*
    };
}

from_num!(Integral > i64,
  i32 => IntegralType::Int,
  i64 => IntegralType::Long
);

from_num!(Floating > f64,
  f64 => FloatingType::Double,
  f32 => FloatingType::Float
);