How can I achieve dynamic dispatch?

The code is followed.

And the error message is:

error[E0038]: the trait `Entity` cannot be made into an object
  --> src/main.rs:20:5
   |
20 |     entities: Vec<Box<Entity>>
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Entity` cannot be made into an object
   |
   = note: the trait cannot require that `Self : Sized`

I wonder what is cannot be made into an object? And how can I fix the problem?

Thank you!!!!

play

Need to remove Sized requirement on Entity so it can be turned into a trait object. This is a good treatment on what object safety means.

1 Like