In this post, we will see how to resolve Operator overloading in Rust not working for reference types
Question:
point3.rsBest Answer:
&Point3
is simply a different type from Point3
. You need to implement Sub
for both if you want to use the subtraction operator on both.Copy
on nearly anything where it can be derived.Copy
types by value.impl Sub for &Point3
, but it’s nice to keep for convenience. You can also rewrite that impl in terms of the non-reference impl Sub for Point3
.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com