So, I have a large number of structs that share the same functionality, and I am wondering what is the best way to handle this in rust? I'm coming from a primarily C++ (and related) background with OOP.
Each XXXComponent must implement PartialEq and Hash but specifically based on the id field. What I am doing currently is just hard coding all of them, but since I am repeating the exact same lines of code (and I have a large number of these components), I have a feeling there should be a more intelligent (and succinct) way to write this.
I'm not sure it's the best way, but given that you can't implement traits on other traits without dyn, you could use a macro, and if you use this enough you could just make your own derive(CustomHashable) proc macro:
Thank you all! I think implementing a custom derive macro is probably the best way of doing something like this. Now I just have to learn how rust macros bloody work!
I've been working though the Rust for Rustaceans book and just hit the section macros which is very good! (And the only reason it was front of mind to answer your question)