🦀Compare the Assembly Generated for Static vs Dynamic Dispatch in Rust

Understand the differences between static and dynamic dispatch in Rust

EventHelix
Software Design
1 min readSep 5, 2024

--

Traits in Rust are similar to interfaces in other languages. Traits permit the implementation of a standard interface for multiple types. Developers can then write code based on the traits rather than the concrete types.

When a trait-specified method is called, the compiler will generate code to dispatch the call to the concrete method implementing the trait specification. Rust supports two types of dispatch:

  • Static dispatch is the default dispatch mode when the concrete type can be determined at compile time.
  • Dynamic dispatch is used when the concrete type implementing the trait is not known at compile time.

Click on the following link to explore the generated assembly and learn about how vtables are defined in Rust.

🔗Compare the Assembly Generated for Static vs Dynamic Dispatch in Rust

--

--