rules_derive: simple and fast derive macros using macro_rules
This library allows you to define custom deriving instances using
macro_rules! macros rather than proc-macros. This is often much simpler.
Getting started
Define a deriving macro with macro_rules!():
Then use it under the rules_derive attribute:
The macro definition can be in the same crate or file as its use.
See full examples in the examples directory.
Tutorial
See the announcement blog post for a tutorial.
Parsed syntax
The rules_derive macro parses any enum/struct definition into a simpler-to-parse format, which it then
passes to your macro. The primary transformations it does are:
- Convert all enum/struct syntaxes and named-field/unnamed-field/unit syntaxes into a uniform sum-of-products syntax.
- Convert any generic parameters in the typical ways needed for
implheaders.
The motivation for these transformations is given in the announcement blog post. Here is an example of the effect of this transformation:
// Rust type definition:
// rules_derive-transformed type definition:
This transformed type definition is then passed to your macro. You can see the macro_rules! header
that accepts this transformed type definition on the [rules_derive] documentation.