Procedural Macros, pt. 5: Test Cases

We are going to test the code from our previous post with a couple of different approaches. synstructure::test_derive synstructure::test_derive is a simple macro that evaluates whether our derive function generates...

Procedural Macros, pt. 4: Getters

As we saw earlier a getter is a simple function to access the value of a property on a struct. This could be by copy, reference, slice etc., as our...

Procedural Macros, pt. 3: Code

The synstructure crate provides a good starting point for our derive macro via decl_derive. decl_derive!([propertese, attributes(propertese)] => #[proc_macro_error] derive_propertese); fn derive_propertese(s: synstructure::Structure) -> proc_macro2::TokenStream { // Macro code to be...

Procedural Macros, pt. 2: Setup

And then, there was a library. cargo new --lib propertese Creating a new project that builds a library couldn’t be simpler. The above command does just that - creates a...

Procedural Macros, pt. 1: An Introduction

Macros, declarative or procedural, are mechanisms in rust that use a few input keywords to generate blocks of code. In this series of posts, we are going to build a...