1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use crate::algorithms::factorization::wheel_factorization;
pub trait Factorizable: Sized {
    type Factors: IntoIterator<Item = Self>;

    fn factors(&self) -> Self::Factors;
}

macro_rules! impl_factorizable_int {
    ($($set:ty)*) => {
        $(
            impl Factorizable for $set {
                type Factors = Vec<Self>;

                #[inline]
                fn factors(&self) -> Self::Factors {
                    wheel_factorization(*self as u64).iter().map(|e| *e as $set).collect()
                }
            }
        )*
    }
}

impl_factorizable_int!(u8 u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize f32 f64);