light_ranged_integers 0.1.1

A Rust library similar to ranged_integers, a bit limited to work on stable rust
Documentation
/*
Copyright © 2024 - Massimo Gismondi

This file is part of light-ranged-integers.

light-ranged-integers is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

light-ranged-integers is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with light-ranged-integers.  If not, see <http://www.gnu.org/licenses/>.
*/

macro_rules! gen_clamp_impl {
($i:ty) => {
paste!{
    // Additions
    impl<const MIN: $i, const MAX: $i> std::ops::Add for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn add(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>) -> Self::Output {
            self + rhs.inner()
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::Add<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn add(self, rhs: $i) -> Self::Output {
            Self::new(self.inner().saturating_add(rhs))
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::AddAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn add_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>)
        {
            *self = *self + rhs;
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::AddAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn add_assign(&mut self, rhs: $i)
        {
            *self = Self::new(self.inner().saturating_add(rhs));
        }
    }


    // Subtraction
    impl<const MIN: $i, const MAX: $i> std::ops::Sub for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn sub(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>) -> Self::Output {
            self - rhs.inner()
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::Sub<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn sub(self, rhs: $i) -> Self::Output {
            Self::new(self.inner().saturating_sub(rhs))
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::SubAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn sub_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>)
        {
            *self -= rhs.inner();
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::SubAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn sub_assign(&mut self, rhs: $i)
        {
            *self = Self::new(self.inner().saturating_sub(rhs));
        }
    }


    // Multiplication
    impl<const MIN: $i, const MAX: $i> std::ops::Mul for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn mul(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>) -> Self::Output {
            self * rhs.inner()
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::Mul<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn mul(self, rhs: $i) -> Self::Output {
            Self::new(self.inner().saturating_mul(rhs))
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::MulAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn mul_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>)
        {
            *self = *self * rhs;
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::MulAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn mul_assign(&mut self, rhs: $i)
        {
            *self = *self * rhs;
        }
    }


    // Division
    impl<const MIN: $i, const MAX: $i> std::ops::Div for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn div(self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>) -> Self::Output {
            self / rhs.inner()
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::Div<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        type Output = Self;
        fn div(self, rhs: $i) -> Self::Output {
            Self::new(self.inner().saturating_div(rhs))
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::DivAssign for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn div_assign(&mut self, rhs: [<Ranged $i:upper>]<MIN,MAX, op_mode::Clamp>)
        {
            *self = *self / rhs;
        }
    }
    impl<const MIN: $i, const MAX: $i> std::ops::DivAssign<$i> for [<Ranged $i:upper>]<MIN, MAX, op_mode::Clamp>
    {
        fn div_assign(&mut self, rhs: $i)
        {
            *self = *self / rhs;
        }
    }
}
};
}