1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
use crate::Vector; use core::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not}; impl<T, const N: usize> Not for Vector<T, N> where T: Not<Output = T>, { type Output = Vector<T, N>; fn not(self) -> Self::Output { self.map(|x| !x) } } impl<T, const N: usize> BitAnd for Vector<T, N> where T: BitAnd<Output = T>, { type Output = Vector<T, N>; fn bitand(self, other: Vector<T, N>) -> Self::Output { self.zip(other).map(|(x, y)| x & y) } } impl<T, const N: usize> BitOr for Vector<T, N> where T: BitOr<Output = T>, { type Output = Vector<T, N>; fn bitor(self, other: Vector<T, N>) -> Self::Output { self.zip(other).map(|(x, y)| x | y) } } impl<T, const N: usize> BitXor for Vector<T, N> where T: BitXor<Output = T>, { type Output = Vector<T, N>; fn bitxor(self, other: Vector<T, N>) -> Self::Output { self.zip(other).map(|(x, y)| x ^ y) } } impl<T, const N: usize> BitAndAssign for Vector<T, N> where T: BitAndAssign, { fn bitand_assign(&mut self, other: Vector<T, N>) { self.iter_mut() .zip(other.into_iter()) .for_each(|(s, y)| *s &= y) } } impl<T, const N: usize> BitOrAssign for Vector<T, N> where T: BitOrAssign, { fn bitor_assign(&mut self, other: Vector<T, N>) { self.iter_mut() .zip(other.into_iter()) .for_each(|(s, y)| *s |= y) } } impl<T, const N: usize> BitXorAssign for Vector<T, N> where T: BitXorAssign, { fn bitxor_assign(&mut self, other: Vector<T, N>) { self.iter_mut() .zip(other.into_iter()) .for_each(|(s, y)| *s ^= y) } } impl<const N: usize> Vector<bool, N> { pub fn any(self) -> bool { self.into_iter().any(|x| x) } } impl<const N: usize> Vector<bool, N> { pub fn all(self) -> bool { self.into_iter().all(|x| x) } }