Macro nullable_wrapper

Source
nullable_wrapper!() { /* proc-macro */ }
Expand description

Create a wrapper enum for switching (internal) implementations efficiently.

When integrating with third-party infrastructure components (HTTP clients, database clients, …), Nullables make use of embedded stubs. This macro generates a wrapper enum for seamlessly switching between the real implementation and the embedded stub.

The macro expects input in the form of an enum declaration, optionally followed by a block of function declarations (like in traits). Each enum variant can either be a newtype variant or a unit variant, which will be transformed a into a newtype variants. The macro creates From<T> and TryInto<T> implementations for each variant.

For each method declaration, the wrapper enum will have a definition that automatically forwards the call to the its variants. If the method does have a default body, this will be used instead of generating the body automatically.