on
Procedural Macros, pt. 2: Setup
And then, there was a library.
cargo new --lib properteseCreating a new project that builds a library couldn’t be simpler. The above
command does just that - creates a folder named propertese, and initializes it
with rust’s default project layout for a library (If you don’t have cargo or
rust installed, they can be installed with rustup).
Inside the folder propertese, we find a Cargo.toml with some default
options.
[package]
name = "propertese"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]We need to indicate we are writing a procedural macro. Edit Cargo.toml to add
the following snippet.
[lib]
proc-macro = trueTo ease development, let’s pull in the following dependencies. The linked documentation for each crate does a very good job of explaining its functionality.
cargo add proc-macro2 synstructure syn quote proc-macro-errorThat concludes our initial setup - short and sweet. We are now good to start writing code in the next installment.