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
use std::ops::Mul;

use crate::Vector;

pub trait VMul<Rhs>: Vector
where Self::Output: Vector
{
    type Output;

    /// Returns the product of a vector-array and a scalar
    /// 
    /// ua
    /// 
    /// # Arguments
    /// 
    /// * `rhs` - A scalar
    /// 
    /// # Examples
    /// 
    /// ```rust
    /// let u = [1.0, 2.0];
    /// let a = 2.0
    /// let ua = [u[0]*a, u[1]*a];
    /// assert_eq!(u.mul(a), ua);
    /// ```
    fn mul(&self, rhs: Rhs) -> Self::Output;
}

impl<F, R, const N: usize> VMul<R> for [F; N]
where
    Self: Vector,
    [<F as Mul<R>>::Output; N]: Vector,
    F: Mul<R> + Clone,
    R: Clone
{
    type Output = [<F as Mul<R>>::Output; N];
    fn mul(&self, rhs: R) -> Self::Output
    {
        array_init::array_init(|i| self[i].clone()*rhs.clone())
    }
}