Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardRustZero-cost abstraction in codegenSingle-choice MCQ

Calling a generic function via static dispatch `process::<Concrete>(x)` versus via a trait object `process_dyn(&x as &dyn Trait)` differ in cost. What is the precise codegen difference and a hidden cost of the static path?

fn process<T: Trait>(x: T) { x.method(); } // monomorphized fn process_dyn(x: &dyn Trait) { x.method(); } // vtable