use crate::op_mode;
use crate::ranged::{
RangedI16, RangedI32, RangedI64, RangedI8, RangedU16, RangedU32, RangedU64, RangedU8
};
use paste::paste;
macro_rules! gen_panic_impl {
($i:ty) => {
paste!{
impl<const MIN: $i, const MAX: $i> std::ops::Add for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn add(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>) -> Self::Output {
self + rhs.inner()
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Add<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn add(self, rhs: $i) -> Self::Output {
Self::new(self.inner().checked_add(rhs).unwrap())
}
}
impl<const MIN: $i, const MAX: $i> std::ops::AddAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn add_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>)
{
*self += rhs.inner();
}
}
impl<const MIN: $i, const MAX: $i> std::ops::AddAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn add_assign(&mut self, rhs: $i)
{
*self = Self::new(self.inner().checked_add(rhs).unwrap());
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Sub for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn sub(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>) -> Self::Output {
self - rhs.inner()
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Sub<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn sub(self, rhs: $i) -> Self::Output {
Self::new(self.inner().checked_sub(rhs).unwrap())
}
}
impl<const MIN: $i, const MAX: $i> std::ops::SubAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn sub_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>)
{
*self -= rhs.inner();
}
}
impl<const MIN: $i, const MAX: $i> std::ops::SubAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn sub_assign(&mut self, rhs: $i)
{
*self = Self::new(self.inner().checked_sub(rhs).unwrap());
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Mul for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn mul(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>) -> Self::Output {
self * rhs.inner()
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Mul<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn mul(self, rhs: $i) -> Self::Output {
Self::new(self.inner().checked_mul(rhs).unwrap())
}
}
impl<const MIN: $i, const MAX: $i> std::ops::MulAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn mul_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>)
{
*self = Self::new(self.inner().checked_mul(rhs.inner()).unwrap());
}
}
impl<const MIN: $i, const MAX: $i> std::ops::MulAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn mul_assign(&mut self, rhs: $i)
{
*self = Self::new(self.inner().checked_mul(rhs).unwrap());
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Div for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn div(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>) -> Self::Output {
self / rhs.inner()
}
}
impl<const MIN: $i, const MAX: $i> std::ops::Div<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
type Output = Self;
fn div(self, rhs: $i) -> Self::Output {
Self::new(self.inner().checked_div(rhs).unwrap())
}
}
impl<const MIN: $i, const MAX: $i> std::ops::DivAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn div_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Panic>)
{
*self = Self::new(self.inner().checked_div(rhs.inner()).unwrap());
}
}
impl<const MIN: $i, const MAX: $i> std::ops::DivAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Panic>
{
fn div_assign(&mut self, rhs: $i)
{
*self = Self::new(self.inner().checked_div(rhs).unwrap());
}
}
}
};
}
gen_panic_impl!(u8);
gen_panic_impl!(u16);
gen_panic_impl!(u32);
gen_panic_impl!(u64);
gen_panic_impl!(i8);
gen_panic_impl!(i16);
gen_panic_impl!(i32);
gen_panic_impl!(i64);