
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.

Rust enums carry data in each variant, which replaces the class hierarchy and the nullable field. See the syntax, match, methods, and where it beats inheritance.