How can I rethink/rewrite something as simple as this?
use std::ops::{Add, Sub, Mul, Div};
pub struct A<T> {
x: T
}
impl<T> A<T> where T: Mul<T, Output = T> {
pub fn get_square(&self) -> T { self.x * self.x }
}
<anon>:8:37: 8:41 error: cannot move out of borrowed content
<anon>:8 pub fn get_square(&self) -> T { self.x * self.x }
^~~~
<anon>:8:46: 8:50 error: cannot move out of borrowed content
<anon>:8 pub fn get_square(&self) -> T { self.x * self.x }
^~~~
error: aborting due to 2 previous errors
playpen: application terminated with error code 101
I really don't get it, what's the correct way to operate on struct fields through traits to compute another struct field?
I've seen that the problem has to do with the generic type T, but how can I make struct A generic on T?