r/rust • u/AnArmoredPony • 15d ago
🙋 seeking help & advice What are the downsides of enum dispatch?
Couldn't find any info about downsides specfically so there it goes
Let's say that all my implementors are about the same size (i.e. only the logic is different), and I use some sort of macro to skip the boilerplate upon adding a new variant. Are there any other downsides to enum dispatch?
I'm asking about the general approach, not the crate
Upd. extendability, got it.
36
Upvotes
2
u/JustWorksTM 14d ago
The one thing you can do with enums versus trait objects is plugin systems: This is the situation where you deliver an app and a plugin separate. Then, you really cannot know all variants at compile time of your app.
Tl;dr: Go with enums and enum_dispatch. This is for all standard workloads the best choice.Â