I'm stuck with this code for operator overloading.
use std::ops::Add;
struct Test<T: Add>{
m:T
}
impl<T:Add> Add for Test<T>{
type Output = Test<T>;
fn add(self, rhs: Test<T>) -> Test<T> {
Test { m: (self.m + rhs.m) as T }
}
}
I cannot cast (self.m + rhs.m)
to T
because it is a non-scalar cast
.
Is there a trait for types scalar-castable to T
?