Error while using operators on Generic Type

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 of std::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);
}

Please use code blocks for both the errors and pieces of code.

```
// your code here
```
struct Rightangletriangle<T,U>{
    b: T,
    p: U
    }

    impl<T:Into<f64> + Copy, U:Into<f64> + Copy>  Rightangletriangle<T,U>
{
    fn hypotenuse(&self) -> f64 
    {
        (self.b.into().powi(2) + self.p.into().powi(2)).sqrt()
    }

}

    fn main(){
    let hypo= Rightangletriangle{
    b: 5,
    p:10.5
    };

    let hyp = hypo.hypotenuse();
    println!("{}",hyp);
    }

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.