implement mul + div only for scalars (otherwise conflicting implementations)
This commit is contained in:
parent
338669b60f
commit
021d7f9d1f
@ -127,13 +127,16 @@ macro_rules! impl_vector {
|
||||
$crate::impl_vector_operator!(Add, add );
|
||||
$crate::impl_vector_assign_operator!(SubAssign, sub_assign );
|
||||
$crate::impl_vector_operator!(Sub, sub );
|
||||
$crate::impl_vector_assign_operator!(MulAssign, mul_assign );
|
||||
$crate::impl_vector_operator!(Mul, mul );
|
||||
$crate::impl_vector_assign_operator!(DivAssign, div_assign );
|
||||
$crate::impl_vector_operator!(Div, div );
|
||||
$crate::impl_vector_assign_operator!(RemAssign, rem_assign );
|
||||
$crate::impl_vector_operator!(Rem, rem );
|
||||
|
||||
// mul and div are special, usually you multiply by a scalar
|
||||
// and implementing both vec*vec and vec*scalar is conflicting implementations Q_Q
|
||||
$crate::impl_vector_assign_operator_scalar!(MulAssign, mul_assign );
|
||||
$crate::impl_vector_operator_scalar!(Mul, mul );
|
||||
$crate::impl_vector_assign_operator_scalar!(DivAssign, div_assign );
|
||||
$crate::impl_vector_operator_scalar!(Div, div );
|
||||
|
||||
// Impl bitwise operators
|
||||
$crate::impl_vector_assign_operator!(BitAndAssign, bitand_assign );
|
||||
$crate::impl_vector_operator!(BitAnd, bitand );
|
||||
@ -151,6 +154,19 @@ macro_rules! impl_vector {
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_vector_operator_scalar {
|
||||
($trait: ident, $method: ident ) => {
|
||||
impl<const N:usize,T:core::ops::$trait<U,Output=V>,U:Copy,V> core::ops::$trait<U> for Vector<N,T>{
|
||||
type Output=Vector<N,V>;
|
||||
#[inline]
|
||||
fn $method(self,rhs:U)->Self::Output{
|
||||
self.map(|t|t.$method(rhs))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_vector_operator {
|
||||
($trait: ident, $method: ident ) => {
|
||||
impl<const N:usize,T:core::ops::$trait<U,Output=V>,U,V> core::ops::$trait<Vector<N,U>> for Vector<N,T>{
|
||||
@ -171,6 +187,19 @@ macro_rules! impl_vector_operator {
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_vector_assign_operator_scalar {
|
||||
($trait: ident, $method: ident ) => {
|
||||
impl<const N:usize,T:core::ops::$trait<U>,U:Copy> core::ops::$trait<U> for Vector<N,T>{
|
||||
#[inline]
|
||||
fn $method(&mut self,rhs:U){
|
||||
self.array.iter_mut()
|
||||
.for_each(|t|t.$method(rhs))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#[doc(hidden)]
|
||||
#[macro_export(local_inner_macros)]
|
||||
macro_rules! impl_vector_assign_operator {
|
||||
($trait: ident, $method: ident ) => {
|
||||
impl<const N:usize,T:core::ops::$trait<U>,U> core::ops::$trait<Vector<N,U>> for Vector<N,T>{
|
||||
|
Loading…
Reference in New Issue
Block a user