• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Operator overloading in Rust not working for reference types

Resolved: Operator overloading in Rust not working for reference types

0
By Isaac Tonny on 15/03/2023 Issue
Share
Facebook Twitter LinkedIn

In this post, we will see how to resolve Operator overloading in Rust not working for reference types

Question:

point3.rs
main.rs
Error
How can I resolve this error?

Best 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.
Separately, it’s good to derive Copy on nearly anything where it can be derived.
Then you can follow the idiomatic practice of taking Copy types by value.
If you use this, you no longer need the 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

operator-overloading reference rust
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Kivy widget hierarchy not behaving as expected

24/03/2023

Resolved: Pandas Groupby Get Values from Previous Group

24/03/2023

Resolved: Can’t access static methods from outside until JavaScript’s static block is over?

24/03/2023

Comments are closed.

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.