I'm not new to Rust, but I am new to using operator overloading in Rust. Say I have a simple Vec3f struct. I want to do something straightforward like:
impl ops::Add<Vec3f> for Vec3f {
type Output = Vec3f;
fn add(self, b: Vec3f) -> Vec3f {
Vec3f {
x : self.x + b.x,
y : self.y + b.y,
z : self.z + b.z
}
}
}
However, the compiler complained if one of the variables passed to the operator overload was borrowed. That can be solved by creating a separate overload for when operators are borrowed, but then I have to maintain 4 separate operator overloads depending on the borrowed state of the two variables.
Is there a better way to handle this? Maybe something I haven't considered using generics?