#[cfg(test)]
mod tests;
mod add;
use super::*;
use core::{
num::{NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8},
ops::{Div, Mul, Neg, Rem, Sub},
};
macro_rules! impl_integer_ops {
($($t:ident, $inner:ident),+) => {
$(
impl_integer_ops![ops: $t, $inner];
)+
};
(ops: $t:ident, $inner:ident) => {
impl_integer_ops![bin_ops: $t, $inner, Sub, sub, Mul, mul, Div, div, Rem, rem];
impl_integer_ops![un_op: $t, $inner, Neg, neg];
};
(bin_ops: $t:ident, $inner:ident, $($op:ident, $fn:ident),+) => {
$(
impl_integer_ops![bin_op: $t, $inner, $op, $fn];
)+
};
(bin_op: $t:ident, $inner:ident, $op:ident, $fn:ident) => {
impl $op for $t {
type Output = $t;
fn $fn(self, rhs: Self::Output) -> Self::Output {
$t($inner::new(self.0.get().$fn(rhs.0.get())).expect("Invalid value 0."))
}
}
};
(un_op: $t:ident, $inner:ident, $op:ident, $fn:ident) => {
impl $op for $t {
type Output = $t;
fn $fn(self) -> Self::Output {
$t($inner::new(self.0.get().$fn()).expect("Invalid value 0."))
}
}
};
}
impl_integer_ops![
NonZeroInteger8,
NonZeroI8,
NonZeroInteger16,
NonZeroI16,
NonZeroInteger32,
NonZeroI32,
NonZeroInteger64,
NonZeroI64,
NonZeroInteger128,
NonZeroI128
];