I am having a hard time wrapping my head around how to design with traits for composition rather than inheritance. My design is heavily modular, and that may be complicating things. I thought I was on a roll until I discovered something I didn’t expect:
impldeclared anywhere in the code will get implemented, despite if it exists inside of a conditional
ifstatement or even a function that never gets called.
I got very close to implementing inheritance in Rust. Here is a more detailed write-up with what I’m working on and code samples: https://stackoverflow.com/questions/45113763/rust-conditional-trait-implementation
Before I get around to studying composition methodologies and refactoring,
- Is there a fix for my case?
- Is there a composition methodology I should look at for my case?
- What are some good composition methodologies? Good resources for studying them?
Thanks Open for any discussion!
The solution is Specialization, which plays much more nicely with Rust’s paradigm.