Hi
I have two traits that look somewhat like the following:
trait Runner {fn run(&self){}}
trait Hunter {fn hunt(&self){}}
Now I want to state that every hunter is a runner. For it I write:
impl Runner for Hunter {} //compiler warns that dyn is for some reason required
Then I write some code like this:
struct Dog {}
impl Hunter for Dog {}
Dog{}.run
And I expect any dog to know how to run because it knows how to hunt, as was explicitly stated. But for some reason, compiler freaks out and emits error saying no method named
runfound for struct
Doge in the current scope
.
Am I doing it wrong or is it not possible at all? Also, why compiler wants to put dyn
when you state equivalence for type classes? Would existential dyn Hunter
and universal Dog
types be equal, such that run()
member would inhabit both or only the former one?