use super::Matrix;
macro_rules! impl_from {
($from:ident, $to:ident) => {
impl From<Matrix<$from>> for Matrix<$to> {
fn from(f: Matrix<$from>) -> Self {
Matrix {
rows: f.rows,
cols: f.cols,
data: f.into_iter().map($to::from).collect(),
}
}
}
impl<'a> From<&'a Matrix<$from>> for Matrix<$to> {
fn from(f: &'a Matrix<$from>) -> Self {
Matrix {
rows: f.rows,
cols: f.cols,
data: f.into_iter().map(|n| $to::from(*n)).collect(),
}
}
}
};
($from:ident, $to:ident, $($more:ident),* ) => {
impl_from!($from, $to);
impl_from!($from, $($more),*);
};
}
impl_from!(u8, u16, u32, u64, u128, usize);
impl_from!(u16, u32, u64, u128);
impl_from!(u32, u64, u128);
impl_from!(u64, u128);
impl_from!(i8, i16, i32, i64, i128, isize);
impl_from!(i16, i32, i64, i128);
impl_from!(i32, i64, i128);
impl_from!(i64, i128);
impl_from!(u8, i16, i32, i64, i128);
impl_from!(u16, i32, i64, i128);
impl_from!(u32, i64, i128);
impl_from!(u64, i128);
impl_from!(u16, usize);
impl_from!(u8, isize);
impl_from!(i16, isize);
impl_from!(i8, f32, f64);
impl_from!(i16, f32, f64);
impl_from!(i32, f64);
impl_from!(u8, f32, f64);
impl_from!(u16, f32, f64);
impl_from!(u32, f64);
impl_from!(f32, f64);