Hey there,
I spent the last couple of weeks reading the Book and after that, I started making some simple exercises, right now I'm stuck with a problem that involves Traits.
For this exercise I want to create a Farm generic trait and the data type bound must be another trait (with fantasy I called it Animal).
I defined the traits as follows:
The first two functions are easy to implement, I will just need to mutate the internal HashMap to add or remove animals.
But I don't know how to implement the merge_farm function. Well I know the logic, add animals from both farms into a new one but how can I create the farm struct and return it?
And second question: why the compiler is telling me to use the keyword dyn in the second parameter and in the type to return?
This type seems really confused to me. You see, the dyn keyword is only used to specify you want to use a trait object i.e. dynamic dispatch. But that only works with traits.
Assuming Farm<T> is indeed a type, the suggestion makes no sense. Even if the type was a dynamically-sized type (DST), I wouldn't expect a suggestion to add the dyn keyword.