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::Div;
use crate::Vector;
pub trait VDiv<Rhs>: Vector
where Self::Output: Vector
{
type Output;
/// Returns the vector-array divided by a scalar
///
/// u/b
///
/// # Arguments
///
/// * `rhs` - A scalar
///
/// # Examples
///
/// ```rust
/// let u = [1.0, 2.0];
/// let b = 2.0
/// let u_b = [u[0]/b, u[1]/b];
/// assert_eq!(u.div(b), u_b);
/// ```
fn div(&self, rhs: Rhs) -> Self::Output;
}
impl<F, R, const N: usize> VDiv<R> for [F; N]
where
Self: Vector,
[<F as Div<R>>::Output; N]: Vector,
F: Div<R> + Copy,
R: Copy
{
type Output = [<F as Div<R>>::Output; N];
fn div(&self, rhs: R) -> Self::Output
{
self.map(|x| x/rhs)
}
}