What is the difference between `’a.` and `type a.` and when to use each?

Below are alternative explanations with a varying amount of detail, depending on how much of a hurry you’re in. 😉 I will use the following code (drawn from that other question) as a running example. Here, the type annotation on the definition of reduce is actually required to make it typecheck. (* The type [(‘a, … Read more

Vector of objects belonging to a trait

Vec<Animal> is not legal, but the compiler can’t tell you that because the type mismatch somehow hides it. If we remove the calls to push, the compiler gives us the following error: <anon>:22:9: 22:40 error: instantiating a type parameter with an incompatible type `Animal`, which does not fulfill `Sized` [E0144] <anon>:22 let mut v: Vec<Animal> … Read more