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_binary_op {
    (+, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Add, add, $($t)+););
    (-, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Sub, sub, $($t)+););
    (*, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Mul, mul, $($t)+););
    (/, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Div, div, $($t)+););
    (%, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Rem, rem, $($t)+););
    (&, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, BitAnd, bitand, $($t)+););
    (|, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, BitOr, bitor, $($t)+););
    (^, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, BitXor, bitxor, $($t)+););
    (<<, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Shl, shl, $($t)+););
    (>>, $($t:tt)+) => ($crate::_impl_binary_op_internal!(ops, Shr, shr, $($t)+););
    (dot, $($t:tt)+) => ($crate::_impl_binary_op_internal!(self, Dot, dot, $($t)+););
    (dot_clamp, $($t:tt)+) => ($crate::_impl_binary_op_internal!(self, DotClamp, dot_clamp, $($t)+););
    (cross, $($t:tt)+) => ($crate::_impl_binary_op_internal!(self, Cross, cross, $($t)+););
}

#[doc(hidden)]
#[macro_export]
macro_rules! _impl_binary_op_internal {
    ($path:ident, $ops_trait:ident, $ops_fn:ident, &$lhs:ty, &$rhs:ty, $out:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => {
        $crate::_impl_binary_op_borrowed_borrowed!(
            $path, $ops_trait, $ops_fn, $lhs, $rhs, $out, $lhs_i, $rhs_i, $body
        );
    };
    ($path:ident, $ops_trait:ident, $ops_fn:ident, &$lhs:ty, $rhs:ty, $out:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => {
        $crate::_impl_binary_op_borrowed_owned!(
            $path, $ops_trait, $ops_fn, $lhs, $rhs, $out, $lhs_i, $rhs_i, $body
        );
    };
    ($path:ident, $ops_trait:ident, $ops_fn:ident, $lhs:ty, &$rhs:ty, $out:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => {
        $crate::_impl_binary_op_owned_borrowed!(
            $path, $ops_trait, $ops_fn, $lhs, $rhs, $out, $lhs_i, $rhs_i, $body
        );
    };
    ($path:ident, $ops_trait:ident, $ops_fn:ident, $lhs:ty, $rhs:ty, $out:ty, $lhs_i:ident, $rhs_i:ident, $body:block) => {
        $crate::_impl_binary_op_owned_owned!(
            $path, $ops_trait, $ops_fn, $lhs, $rhs, $out, $lhs_i, $rhs_i, $body
        );
    };
}

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

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

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

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