15
Patterns for Modeling Overlapping Variant Data in Rust
(mcmah309.github.io)
Welcome to the Rust community! This is a place to discuss about the Rust programming language.
Credits
This was a good blog post. I have started using approach #3 as well for just about every situation where I was originally planning on just using a enum type by itself. Inevitably I end up needing to apply shared state to all of my enums (create date, parent table ID, etc.) and this approach has really worked out very well. You can also add some convenience functions for returning if the kind is one of the variants (ex:
IsKeywordSearch
) to make if-statements easier to read (and a match on the type enum is overly verbose when you don't need the properties contained within the enum itself).