auto_ops_det 2.0.0

Macros for easy operator overloading.
Documentation
// Copyright (C) 2020-2025 glam-det authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#[doc(hidden)]
#[macro_export]
macro_rules! _parse_assignment_op {
    (+=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, AddAssign, add_assign, $($t)+););
    (-=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, SubAssign, sub_assign, $($t)+););
    (*=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, MulAssign, mul_assign, $($t)+););
    (/=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, DivAssign, div_assign, $($t)+););
    (%=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, RemAssign, rem_assign, $($t)+););
    (&=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, BitAndAssign, bitand_assign, $($t)+););
    (|=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, BitOrAssign, bitor_assign, $($t)+););
    (^=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, BitXorAssign, bitxor_assign, $($t)+););
    (<<=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, ShlAssign, shl_assign, $($t)+););
    (>>=, $($t:tt)+) => ($crate::_impl_assignment_op_internal!(ops, ShrAssign, shr_assign, $($t)+););
}

#[doc(hidden)]
#[macro_export]
macro_rules! _impl_assignment_op_internal {
    ($path:ident, $ops_trait:ident, $ops_fn:ident, $lhs:ty, &$rhs:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => {
        impl $path::$ops_trait<&$rhs> for $lhs {
            #[inline]
            fn $ops_fn(&mut self, $rhs_i: &$rhs) {
                let mut $lhs_i = self;
                $body
            }
        }

        impl $path::$ops_trait<&$rhs> for &mut $lhs {
            #[inline]
            fn $ops_fn(&mut self, $rhs_i: &$rhs) {
                let mut $lhs_i = self;
                $body
            }
        }
    };
    ($path:ident, $ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => {
        impl $path::$ops_trait<$rhs> for $lhs {
            #[inline]
            fn $ops_fn(&mut self, $rhs_i: $rhs) {
                let mut $lhs_i = self;
                $body
            }
        }

        impl $path::$ops_trait<$rhs> for &mut $lhs {
            #[inline]
            fn $ops_fn(&mut self, $rhs_i: $rhs) {
                let mut $lhs_i = self;
                $body
            }
        }
    };
}