Hello. I want to store generic trait implementation in HashMap. Is it possible? At the moment I don't understand what type I need to provide to HashMap to achieve my goal.
Here is an example of what I want: https://gist.github.com/lavrxxx/cc639b19a8aebb4eb86417c21851d980.
It's not possible to substitute a generic type parameter with more than one type; therefore, you can't store values of different types in a HashMap.
If you are willing to accept dynamic dispatch, and your trait allows it (is "object-safe"), then you can store (boxed) trait objects, dyn Trait
.
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.