rust-by-practice icon indicating copy to clipboard operation
rust-by-practice copied to clipboard

fix: provide solution that satisfies requirement

Open pabigot opened this issue 2 years ago • 1 comments

The specification says we have to return something that implements Animal, but can't tell which at compile time. The existing solution only returns one concrete type Sheep, while the intent was to return either Sheep or Cow. This requires type erasure that can only be done with a reference to dyn trait.

pabigot avatar Jul 20 '22 22:07 pabigot

After reviewing the surrounding text it's clear this isn't the right solution, but then the exercise asks for something that can't be done: use impl Trait to return values for which the type can't be determined at compile time.

pabigot avatar Jul 22 '22 14:07 pabigot