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
use {c32, c64};

/// An element.
pub trait Element: Copy + PartialEq {
    /// Check if the element is zero.
    fn is_zero(&self) -> bool;

    /// Return the zero element.
    fn zero() -> Self;
}

macro_rules! implement(
    ($name:ty, $zero:expr) => (
        impl Element for $name {
            #[inline(always)]
            fn is_zero(&self) -> bool {
                *self == $zero
            }

            #[inline(always)]
            fn zero() -> Self {
                $zero
            }
        }
    );
    ($name:ty) => (
        implement!($name, 0);
    );
);

implement!(u8);
implement!(u16);
implement!(u32);
implement!(u64);

implement!(i8);
implement!(i16);
implement!(i32);
implement!(i64);

implement!(f32, 0.0);
implement!(f64, 0.0);

implement!(isize);
implement!(usize);

implement!(c32, c32::new(0.0, 0.0));
implement!(c64, c64::new(0.0, 0.0));