I'm writing some trait about Linear Space. This set of traits ensures that:
If some type T meets the requirement of &T:Add<Output=T>
, &T:Sub<Output=T>
, and &T:Mul<Num, Output=T>
, then it can impl my LinearSpace
trait.
So that I write
pub trait LinearSpace<Scalar>
where
Scalar: Num,
Self: Sized,
for<'a> &'a Self: Add<Output = Self>,
for<'a> &'a Self: Sub<Output = Self>,
for<'a> &'a Self: Mul<Scalar, Output = Self>,
{
}
Then I have some function say foo
, which accepts a parameter of LinearSpace:
fn foo<Scalar, T>(x:&T)
where T:LinearSpace<Scalar>,
Scalar: Num+Sized
{
...
}
It is rather nature isn't it? But it's wrong. Rustc requires me to write
fn foo<Scalar, T>(x:&T)
where T:LinearSpace<Scalar>,
Scalar: Num+Sized,
for<'a> &'a T: Add<Output = T>,
for<'a> &'a T: Sub<Output = T>,
for<'a> &'a T: Mul<Scalar, Output = T>,
{
...
}
Is it possible to not write
for<'a> &'a T: Add<Output = T>,
for<'a> &'a T: Sub<Output = T>,
for<'a> &'a T: Mul<Scalar, Output = T>,
in the definition of above function?
Thanks.