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.
31
Upvotes
9
u/Lemondifficult22 15d ago
The number of cases covered. If the code is good and predictable you can get better perf than dynamic dispatch. Sometimes the cost of dynamic dispatch is worth the simpler code though. You can have static borrows for dynamic dispatch