Skip to content

JohnScience/proc_macro_template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 

Repository files navigation

proc_macro_template

License: MIT

Cookiecutter template for creating procedural macros in Rust programming language.

Requirements

In order to use the template, you need to have cookiecutter installed. If needed, check out the Installation section of the docs.

Usage

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 are strum, cfg-if, and rand_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 in cookiecutter.json for an example.
  • use_shorthands_for_proc_macro_crates - whether use identifiers pm and pm2 instead of proc_macro and proc_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

About the template

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.

Generated project example

Example of a project generated using this cookiecutter is available here.

On (in)stability of cookiecutter.json

As mentioned in issue #1 "Making input easier", the author believes the input could be made easier. Consequently, cookiecutter.json can change.

Notes

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.

About

Cookiecutter template for creating procedural macros

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published