Mykhailo Maidan

Crafting Custom Frameworks with Rust: A Deep Dive into Procedural Macros

What if your Rust macros could share context across your entire crate? Learn how a pre-compilation metadata pass unlocks powerful, boilerplate-free APIs.

Crafting Custom Frameworks with Rust: A Deep Dive into Procedural Macros
#1about 7 minutes

Exploring the power and pitfalls of Rust macros

Rust's metaprogramming capabilities allow for reducing boilerplate code, but macros can be complex to write, debug, and test.

#2about 6 minutes

Simplifying event handlers with custom attribute macros

An event-driven framework's API can be significantly simplified by using attribute macros to define event handlers and their corresponding events.

#3about 7 minutes

Overcoming unordered macro expansion with build-time metadata

To solve the problem of unordered macro expansion, a build script (`build.rs`) can analyze the source code and generate a metadata file before compilation.

#4about 8 minutes

Parsing crate source code with the `syn` crate

The `syn` and `syn-inline-mod` crates enable parsing an entire Rust crate into a single Abstract Syntax Tree (AST), which can then be analyzed using the visitor pattern.

#5about 5 minutes

Loading metadata and modifying the AST in macros

Procedural macros can load the pre-generated metadata from disk and use the `VisitMut` trait from `syn` to modify the AST, such as renaming functions to simulate overloading.

#6about 8 minutes

Evaluating the trade-offs of a metadata-driven macro framework

While this metadata-driven approach offers powerful compile-time checks and extensibility for tooling, it increases build times and implementation complexity.

#7about 12 minutes

Q&A on testing, nightly Rust, and framework design

The discussion covers practical considerations like the necessity of nightly Rust for certain features, strategies for testing complex macros, and potential runtime optimizations.

Related jobs
Jobs that call for the skills explored in this talk.

Featured Partners

Related Articles

View all articles
BR
Benjamin Ruschin
What Developers Really Need to Create Great Code Demos
Every developer on earth has, at some point, had another developer to thank for a breakthrough, a success, an aha moment they wouldn’t have had without coming across that blog post, that open-source contribution, that reply on socials or that humble ...
What Developers Really Need to Create Great Code Demos
CH
Chris Heilmann
With AIs wide open - WeAreDevelopers at All Things Open 2025
Last week our VP of Developer Relations, Chris Heilmann, flew to Raleigh, North Carolina to present at All Things Open . An excellent event he had spoken at a few times in the past and this being the “Lucky 13” edition, he didn’t hesitate to come and...
With AIs wide open - WeAreDevelopers at All Things Open 2025
DC
Daniel Cranney
Building AI Solutions with Rust and Docker
In recent years, artificial intelligence has surged in popularity in the world of development. While Python remains a popular choice in the realm of AI, Rust - often known as Rust Lang - is quickly emerging as a formidable alternative.Rust programmin...
Building AI Solutions with Rust and Docker

From learning to earning

Jobs that call for the skills explored in this talk.

Rust and GoLang

Rust and GoLang

NHe4a GmbH
Karlsruhe, Germany

Remote
55-65K
Intermediate
Senior
Go
Rust
Rust Developer

Rust Developer

Hays Specialist Recruitment

Remote
C
GIT
Java
Bash
+3
Rust Engineer

Rust Engineer

Staking Facilities GmbH
München, Germany

Remote
48-67K
API
Blockchain
Microservices