Dynamic dispatch
Dynamic dispatch is runtime selection of an operation implementation according to an object's dynamically determined type or runtime arguments.
Data-Oriented Programming: Reduce software complexity
Dynamic dispatch is runtime selection of an operation implementation based on runtime argument information rather than only static types.
- How it is used
- Uses runtime data to extend polymorphic behavior beyond single- and multiple-argument type selection.
- How deep it goes
- Explains dispatch functions, validation, emitted values, method wiring, defaults, and testing through a complete example.
- Examples
- Demonstrates dysGreet with dog, cat, and cow maps, combining animal type with whether a name exceeds five letters.
- What you can do after
- Build it from scratch with a dispatch function and methods keyed by runtime values.
Read how Data-Oriented Programming: Reduce software complexity explains dynamic dispatch →
Idiomatic Rust
Dynamic dispatch is runtime selection of an implementation based on the concrete type behind an interface value.
- How it is used
- Stores different concrete types behind one trait interface and calls shared trait methods at runtime.
- How deep it goes
- Explains `dyn` trait objects, vtable-based lookup, and pointer requirements for unsized values.
- Examples
- Demonstrates two structs in a boxed trait-object vector and dispatches their shared method.
- What you can do after
- Build a heterogeneous `Vec<Box<dyn MyTrait>>` and invoke the shared trait method.
Also covered in
- Learn Rust in a Month of Lunches
- Learn C++ by Example
- Rust in Action: Systems programming concepts and techniques
What to know first
- heapA heap is a runtime memory region from which dynamically allocated data is obtained and whose allocation and lifetime are managed separately from function call frames.
- stackA stack is a last-in, first-out data structure in which elements are added and removed at the same end.
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- traitA trait is a type-level construct that defines reusable behavior or members that types can implement or compose.
Related concepts
- trait objectused by · A Rust trait object is a value accessed through a trait interface with its concrete implementing type hidden and methods dispatched dynamically.
- Boxused by · Box is a Rust owning smart pointer that provides indirection by storing a uniquely owned value in heap-allocated memory.
- polymorphismkind of · Polymorphism is a programming-language capability that lets a common operation or interface work with values of different types, with behavior or implementation determined by the type or value.
- vtableimplemented by · A vtable is a compiler- or runtime-generated table of function or method entries used to dynamically dispatch operations for polymorphic objects or types.
Questions about dynamic dispatch
What is dynamic dispatch?
Dynamic dispatch is runtime selection of an operation implementation according to an object's dynamically determined type or runtime arguments.
Which Manning books explain dynamic dispatch?
Data-Oriented Programming: Reduce software complexity and Idiomatic Rust.
What should I know before learning dynamic dispatch?
Manning books that teach dynamic dispatch usually introduce heap, stack, array and trait first.
What is the difference between dynamic dispatch and static dispatch?
Dynamic dispatch is runtime selection of an operation implementation according to an object's dynamically determined type or runtime arguments. Static dispatch is the compile-time selection of a function or method implementation based on concrete types.
What is dynamic dispatch a kind of?
Dynamic dispatch is a kind of polymorphism. Polymorphism is a programming-language capability that lets a common operation or interface work with values of different types, with behavior or implementation determined by the type or value.
What is dynamic dispatch also called?
Dynamic dispatch is also called virtual dispatch.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

