impl<'a,T> ops::Add<V2> for &'a mut V2{
type Output=&'a mut V2;
fn add(self,_rhs:V2)->&'a mut V2{
self
}
}
Can somebody maybe help explain whats going on here? This seems very much so overly complex or maybe its just something im missing. All i wanted was a Vector2d struct that could use add operation with other Vector2d - specifically to also mutate the A in A+B.
Which part do you think isn't necessary? After fixing the obvious errors (didn't check), I annotated each element of the code:
// definition of the type itself, which takes a type parameter
struct V2<T> {
x: T,
y: T,
}
// implement Add for &mut V2, with any lifetime 'a and any type T
impl<'a,T> ops::Add<V2<T>> for &'a mut V2<T> {
type Output = &'a mut V2<T>; // where the result type is the same
// this function will be called by the overloaded operator
fn add(self, _rhs: V2<T>) -> &'a mut V2<T> {
self // which apparently just returns the LHS unmodified
}
}
There's nothing in this piece of code that's not needed for expressing what you (seem to) want.