array_matrix/vector/
mul.rs

1use std::ops::Mul;
2
3use crate::Vector;
4
5pub trait VMul<Rhs>: Vector
6where Self::Output: Vector
7{
8    type Output;
9
10    /// Returns the product of a vector-array and a scalar
11    /// 
12    /// ua
13    /// 
14    /// # Arguments
15    /// 
16    /// * `rhs` - A scalar
17    /// 
18    /// # Examples
19    /// 
20    /// ```rust
21    /// let u = [1.0, 2.0];
22    /// let a = 2.0
23    /// let ua = [u[0]*a, u[1]*a];
24    /// assert_eq!(u.mul(a), ua);
25    /// ```
26    fn mul(&self, rhs: Rhs) -> Self::Output;
27}
28
29impl<F, R, const N: usize> VMul<R> for [F; N]
30where
31    Self: Vector,
32    [<F as Mul<R>>::Output; N]: Vector,
33    F: Mul<R> + Clone,
34    R: Clone
35{
36    type Output = [<F as Mul<R>>::Output; N];
37    fn mul(&self, rhs: R) -> Self::Output
38    {
39        array_init::array_init(|i| self[i].clone()*rhs.clone())
40    }
41}