Skip to content
← All tracks

Trait Objects and Dispatch

Rust

Heterogeneous collections and the four-way choice between generics, `&dyn`, `Box<dyn>` and enum dispatch — decided by measurement rather than folklore.

This track is written for Rust, which isn't the mode you're browsing in.

0 / 7 solved · 3 articles
  1. 1. Not solved yet. Box<dyn Trait>: trait objects, DSTs and dynamic dispatch
  2. 2. Not solved yet. Dyn compatibility: the actual rules
  3. 3. Not solved yet. Static vs dynamic dispatch, measured
  4. 4. Not solved yet. Enum dispatch: the third option
  5. 5. Choosing between generics, impl Trait, &dyn, Box<dyn> and enums Read
  6. 6. Monomorphisation: what generics compile to, and what that costs Read
  7. 7. Not solved yet. Dispatch through Rc: Rc<dyn Trait> and shared behaviour
  8. 8. Not solved yet. Trait objects and lifetimes: Box<dyn Trait + 'a>
  9. 9. async fn in traits and RPITIT: what works and what does not Read
  10. 10. Not solved yet. Designing signatures: T, &T, &mut T, impl Into<T>

Check yourself

4 questions · one attempt each

These do not count toward finishing the track. They are here to catch the things that are easy to read past.

0 / 4

You need a collection holding several different types that all implement one trait. What must you use?

Vec<Box<dyn Shape>>
Vec<T> where T: Shape
Question 1 of 4