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
use core::ops::Mul;
use super::Vector;
impl<T: Mul<Output = T>, const N: usize> Mul for Vector<T, { N }> {
type Output = Vector<T, { N }>;
default fn mul(mut self, rhs: Self) -> Self::Output {
self.0
.iter_mut()
.zip(rhs.0.iter())
.for_each(|(v, r)| *v = unsafe { core::ptr::read(v).mul(core::ptr::read(r)) });
self
}
}
impl<T: Mul<T, Output = T> + Clone, const N: usize> Mul<T> for Vector<T, { N }> {
type Output = Vector<T, { N }>;
fn mul(mut self, rhs: T) -> Self::Output {
self.0
.iter_mut()
.for_each(|v| *v = unsafe { core::ptr::read(v).mul(rhs.clone()) });
self
}
}
#[test]
fn one() {
assert_eq!(Vector::from([2]) * Vector::from([2]), Vector::from([4]));
}