diff --git a/linear_ops/src/macros/vector.rs b/linear_ops/src/macros/vector.rs index 37654b6..8d4c7de 100644 --- a/linear_ops/src/macros/vector.rs +++ b/linear_ops/src/macros/vector.rs @@ -141,6 +141,12 @@ macro_rules! impl_vector { $crate::impl_vector_operator!(BitOr, bitor ); $crate::impl_vector_assign_operator!(BitXorAssign, bitxor_assign ); $crate::impl_vector_operator!(BitXor, bitxor ); + + // Impl shift operators + $crate::impl_vector_shift_assign_operator!(ShlAssign, shl_assign); + $crate::impl_vector_shift_operator!(Shl, shl); + $crate::impl_vector_shift_assign_operator!(ShrAssign, shr_assign); + $crate::impl_vector_shift_operator!(Shr, shr); } } #[doc(hidden)] @@ -183,6 +189,46 @@ macro_rules! impl_vector_assign_operator { } } } +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_vector_shift_operator { + ($trait: ident, $method: ident ) => { + impl,U,V> core::ops::$trait> for Vector{ + type Output=Vector; + #[inline] + fn $method(self,rhs:Vector)->Self::Output{ + self.map_zip(rhs,|(a,b)|a.$method(b)) + } + } + impl,V> core::ops::$trait for Vector{ + type Output=Vector; + #[inline] + fn $method(self,rhs:u32)->Self::Output{ + self.map(|t|t.$method(rhs)) + } + } + } +} +#[doc(hidden)] +#[macro_export(local_inner_macros)] +macro_rules! impl_vector_shift_assign_operator { + ($trait: ident, $method: ident ) => { + impl,U> core::ops::$trait> for Vector{ + #[inline] + fn $method(&mut self,rhs:Vector){ + self.array.iter_mut().zip(rhs.array) + .for_each(|(a,b)|a.$method(b)) + } + } + impl> core::ops::$trait for Vector{ + #[inline] + fn $method(&mut self,rhs:u32){ + self.array.iter_mut() + .for_each(|t|t.$method(rhs)) + } + } + } +} #[doc(hidden)] #[macro_export(local_inner_macros)]