`impl Trait` and generics use static dispatch resolved at compile time. `dyn Trait` behind a reference or Box uses a vtable for dynamic dispatch, enabling heterogeneous collections at a small runtime cost. Only object-safe traits can be used as trait objects.
← Rust theorytheory 0/50 · 0%
Abstraction · medium
23. Trait Objects and dyn
Static versus dynamic dispatch.
Check your understanding
1. `Box<dyn Trait>` uses…
2. Trait objects require the trait to be…