enum_inliner
Takes this:
enum_inline!;
And expands each function inside the provided impl block by "copying" its body
— the template — into the match arms generated for the corresponding enum.
One would get this:
See the complete code in this simple example test.
Use cases
Use cases aren't vast; but sometimes this may come in handy.
One of such use cases is when working with traits that aren't
object-safe/dyn-safe (cannot be used with dyn), but still require dynamic
dispatch at runtime. In these situations, one can create an enum with variants
representing each trait implementation, which is used to perform the dispatch
based on the enum "tags", which can pass through runtime.
Why a proc macro?
Even though this kind of functionality can be implemented using a
declarative macro, the macro_rules! implementation becomes extremely
convoluted. User-level error messages also get degraded.
License
MIT license.