use super::IntegerOrFloat;
use super::{f_iof, i_iof};
macro_rules! impl_from_iof_for_primitive {
($primitive:ident) => {
impl From<IntegerOrFloat> for $primitive {
fn from(iof: IntegerOrFloat) -> Self {
match iof {
IntegerOrFloat::Float(f) => f as Self,
IntegerOrFloat::Integer(i) => i as Self,
}
}
}
};
}
macro_rules! impl_from_iof_for_primitives_all {
($($primitive:ident),+) => {
$(
impl_from_iof_for_primitive!($primitive);
)+
}
}
macro_rules! impl_from_integer_for_iof {
($integer_type:ident) => {
impl From<$integer_type> for IntegerOrFloat {
fn from(p: $integer_type) -> Self {
IntegerOrFloat::Integer(i_iof::try_from(p).unwrap())
}
}
};
}
macro_rules! impl_from_integer_for_iof_all {
($($primitive:ident),+) => {
$(
impl_from_integer_for_iof!($primitive);
)+
}
}
macro_rules! impl_from_float_for_iof { ($integer_type:ident) => {
impl From<$integer_type> for IntegerOrFloat {
fn from(p: $integer_type) -> Self {
IntegerOrFloat::Float(p as f_iof)
}
}
};
}
macro_rules! impl_from_float_for_iof_all {
($($primitive:ident),+) => {
$(
impl_from_float_for_iof!($primitive);
)+
}
}
impl_from_iof_for_primitives_all!(i8, i16, i32, i64, isize);
impl_from_iof_for_primitives_all!(u8, u16, u32, u64, usize);
impl_from_iof_for_primitives_all!(f32, f64);
impl_from_integer_for_iof_all!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
impl_from_float_for_iof_all!(f32, f64);