Oriel — AI & technology worth noticing, every day.

Rust Declarative Macros: Organization, Scoping, and Common Use-Cases

Web page · https://sigseis.dev/articles/2026/11/10

First seen by Oriel on .

AI summary

This Rust 2024 article explains how to integrate declarative macros into crates through scoping, exporting, hygiene, and maintainable file organization.

  • Textually scoped macros work only after definition but automatically reach subsequent submodules; path-based scoping uses re-exports and supports normal imports and module paths.
  • The author recommends path-based scoping with `pub(crate) use` for crate-local macros and avoiding legacy `#[macro_use]` patterns where possible.
  • External availability requires `#[macro_export]`, which always exports at the crate root; hidden root names and `pub use` can provide cleaner public module paths.
  • Exported macros should resolve internal items through `$crate` and may use a hidden `__private` module for re-exported dependencies.
  • Macros used broadly should live in separate, predictably named files under an organizational module, while narrowly used macros should remain near their invocation sites.

#rust #declarative macros #macro hygiene #module system

Generated by gpt-5.6-sol. Check the original for details.

Metric trends

Last 30 days · Up to 120 recorded samples per source and metric, with reposts kept separate · First and latest retained

Points

Score reported by the source.

  • Lobsters: 2, latest observation ; +1 over observed period since

Comments

Comment count reported by the source.

  • Lobsters: 1, latest observation ; +1 over observed period since

Aliases

SourceExternal IDURL
Lobsterssnorgihttps://sigseis.dev/articles/2026/11/10 Read discussion