Skip to content

Instantly share code, notes, and snippets.

View turbohz's full-sized avatar
🦀
Full out member of the cult of Rust

Gerard Ruiz turbohz

🦀
Full out member of the cult of Rust
View GitHub Profile
@turbohz
turbohz / how-to-write-hygienic-macros.md
Created June 16, 2024 08:39 — forked from Kestrer/how-to-write-hygienic-macros.md
A guide on how to write hygienic Rust macros

How to Write Hygienic Rust Macros

Macro hygiene is the concept of macros that work in all contexts; they don't affect and aren't affected by anything around them. Ideally all macros would be fully hygienic, but there are lots of pitfalls and traps that make it all too easy to accidentally write unhygienic macros. This guide attempts to provide a comprehensive resource for writing the most hygienic macros.

Understanding the Module System

First, a little aside on the details of Rust's module system, and specifically paths; it is