macro_registry
macro_registry is a small proc-macro infrastructure crate for three related
jobs:
- inspect a Rust source file for enums and structs
- query those items by module and attribute
- cache typed metadata behind a registry with explicit lookup results
It is useful when multiple macros need to discover and reuse the same items in the same file or module without re-implementing lookup and caching logic.
Install
[]
= "0.5.4"
Modules
analysis: cached file analysis for enum and struct discoverycallsite: current source and module helpers for proc-macro call sitesquery: module-aware item search for diagnostics and pre-resolutionregistry: typed registry loading for cached metadata
Typical Flow
Most callers use the crate in this order:
- get a file path and line number from the macro call site
- query the current file for candidate items in one module
- load and cache the typed metadata you actually want
Simple query example:
use ;
# let file_path = "/tmp/lib.rs";
let machines = candidates_in_module;
If you need cached typed lookup instead of a flat candidate list, use the registry layer:
use ;
use ;
;
;
static MACHINES: = new;
let source = new;
let loaded = ?;
Why Use registry
The registry layer is the part that turns a lookup from "maybe found something" into a deterministic contract.
LookupMode::Exact(...): require one moduleLookupMode::AnyModule: search without seeding a fake sentinel keyLookupFailure::NotFound: nothing matchedLookupFailure::Ambiguous: too many candidates matchedSourceContext: run the same lookup logic against an explicit file and line
If you only need candidate lists for diagnostics, query is often enough. If
you are building a multi-macro system that reuses typed metadata, use
registry.
Intended Use
This crate is for proc-macro authors and macro infrastructure, not for general application code. In the Statum workspace it powers the macro metadata layer, but the API is intentionally generic enough for other module-aware proc-macro systems.
Docs
- API docs: https://docs.rs/macro_registry
- Repository: https://github.com/eboody/statum