milp_types/mixed/
convert.rs

1use super::*;
2
3impl From<bool> for MixedValue {
4    fn from(value: bool) -> Self {
5        MixedValue::Boolean(value)
6    }
7}
8
9macro_rules! impl_from_int {
10    ($($t:ty),*) => {
11        $(
12            impl From<$t> for MixedValue {
13                fn from(value: $t) -> Self {
14                    MixedValue::Integer(value.into())
15                }
16            }
17            impl From<&$t> for MixedValue {
18                fn from(value: &$t) -> Self {
19                    MixedValue::Integer(value.clone().into())
20                }
21            }
22        )*
23    };
24}
25
26macro_rules! impl_from_dec {
27    ($($t:ty),*) => {
28        $(
29            impl From<$t> for MixedValue {
30                fn from(value: $t) -> Self {
31                    MixedValue::Decimal(value.into())
32                }
33            }
34            impl From<&$t> for MixedValue {
35                fn from(value: &$t) -> Self {
36                    MixedValue::Decimal(value.clone().into())
37                }
38            }
39        )*
40    };
41}
42
43impl_from_int!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize);
44impl_from_int!(BigInt, BigUint);
45impl_from_dec!(f32, f64);