Cookiecutter template for creating procedural macros in Rust programming language.
In order to use the template, you need to have cookiecutter
installed. If needed, check out the Installation section of the docs.
With cookiecutter
installed,
python -m cookiecutter gh:JohnScience/proc_macro_template
It will prompt you to fill out the cookiecutter variables:
crate_name
- the name of the Rust crate that will be the procedural macro library. Some examples of crate names arestrum
,cfg-if
, andrand_chacha
.crate_name_sep
- the separator that should be used for concatenation of parts in crate names: either_
(underscore) or-
(dash).macro_idents
- identifiers that will be used for creation of macros. They are collected into an object with complex schema. Check the default value incookiecutter.json
for an example.use_shorthands_for_proc_macro_crates
- whether use identifierspm
andpm2
instead ofproc_macro
andproc_macro2
.
For quick prototyping you can use the default values from cookiecutter.json
by appending the --no-input
flag:
python -m cookiecutter gh:JohnScience/proc_macro_template --no-input
The template was inspired by by Carl M. Kadie's article "Nine Rules for Creating Procedural Macros in Rust".
The template consists of the <crate_name>_core
crate that implements the functionality and <crate_name>
crate that exposes the usable procedural macros.
Example of a project generated using this cookiecutter is available here.
As mentioned in issue #1 "Making input easier", the author believes the input could be made easier. Consequently, cookiecutter.json
can change.
This template was created before the author recalled that there's also cargo-generate
, which would allow Rust developers to use only the already available tooling.