aurum-numeric 0.2.0

Numeric traits
Documentation
// Copyright (c) 2016-2017 <daggerbot@gmail.com>
// This software is available under the terms of the zlib license.
// See COPYING.md for more information.

/// Get the additive identity of a numeric type.
pub trait Zero {
    fn zero () -> Self;
}

/// Get the multiplicative identity for a numeric type.
pub trait One {
    fn one () -> Self;
}

macro_rules! impl_zero_one_int {
    ($($ty:ty),*) => { $(
        impl Zero for $ty {
            fn zero () -> $ty { 0 }
        }

        impl One for $ty {
            fn one() -> $ty { 1 }
        }
    )* };
}

macro_rules! impl_zero_one_float {
    ($($ty:ty),*) => { $(
        impl Zero for $ty {
            fn zero () -> $ty { 0.0 }
        }

        impl One for $ty {
            fn one () -> $ty { 1.0 }
        }
    )* };
}

impl_zero_one_int!(i8, i16, i32, i64, isize, u8, u16, u32, u64, usize);
impl_zero_one_float!(f32, f64);