use num_traits::{Float, FromPrimitive};
use std::ops::{Add, Mul, Sub};
pub trait Vector:
Add<Self, Output = Self> +
Sub<Self, Output = Self> +
Mul<Self::Field, Output = Self> +
Sized +
Copy
{
type Field: Float + FromPrimitive + Copy;
fn zero() -> Self;
fn from_usize(u: usize) -> Self::Field {
<Self::Field as FromPrimitive>::from_usize(u)
.expect("usize-to-float conversion failed")
}
}
impl<F> Vector for F
where
F: Float + FromPrimitive + Copy,
{
type Field = F;
#[inline]
fn zero() -> Self {
F::zero()
}
}