
Generics
Enum Dispatch in Rust for Speed Without Trait Objects
When you know every implementor of a trait, an enum can stand in for a trait object with no allocation and with inlinable calls. The cost is a closed set.
7 min read
Tag
2 posts

When you know every implementor of a trait, an enum can stand in for a trait object with no allocation and with inlinable calls. The cost is a closed set.

Static dispatch resolves the call at compile time and dynamic dispatch looks it up in a vtable at run time. See the layout, the cost and when it matters.