Rust is a strange language. I implemented addition of points of different types, only that that types should support addition:
impl<A: Add<B>, B> Add<XY<B>> for XY<A> {
type Output = XY<A::Output>;
fn add(self, rhs: XY<B>) -> Self::Output {
XY::new(self.x + rhs.x, self.y + rhs.y)
}
}
But now it refuses to use variables after addition because they "moved".
impl<A: Add<B>, B> Add<XY<B>> for XY<A> {
type Output = XY<A::Output>;
fn add(self, rhs: XY<B>) -> Self::Output {
XY::new(self.x + rhs.x, self.y + rhs.y)
}
}
But now it refuses to use variables after addition because they "moved".