How can I achieve dynamic dispatch?


#1

The code is followed.

https://play.rust-lang.org/?gist=211845d953cd9012f6f214aa5d81332d&version=stable&mode=debug

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!!!


#2

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.