Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

trait object

A value used only through a trait, whatever its real type.

A trait object (dyn Trait behind a pointer such as &dyn Trait or Box) erases the concrete type and calls methods through a vtable.

Loading interactive…

Examples

  • let channels: Vec<Box<dyn Notifier>> = vec![Box::new(email), Box::new(sms)]; keeps an Email and an Sms in one vector, and c.send(..) works on each.

Read the full section →