i want to calculate hypotenuse by using generic method but get the following error ,
error[E0369]: binary operation
+
cannot be applied to type<T as std::ops::Mul>::Output
--> src\main.rs:24:22
|
24 | (self.bself.b)+(self.pself.p)
| ---------------^--------------- ::Output
| |
| ::Output
|
= note: an implementation ofstd::ops::Add
might be missing for<T as std::ops::Mul>::Output
Code:
struct Rightangletriangle<T,U>{
b: T,
p: U,
}impl<T: Add+Mul, U:Add+Mul> Rightangletriangle<T,U>{
fn hypotenuse(&self) -> T{(self.b*self.b)+(self.p*self.p) }
}
fn main(){
let hypo= Rightangletriangle{
b: 5,
p:10.4
};let hyp = hypo.hypotenuse();
println!("{}",hyp);
}