nestum
nestum makes nested enum paths and matches feel natural, so you can codify invariants by nesting related enums while keeping ergonomic construction and matching.
use ;
let event = Update;
nested!
Instead of:
Documents
you can write:
Update
Where this pays off:
- Event routing and message buses.
- Permission or policy trees (resource + action).
- Parsers/compilers (node + kind).
- UIs with nested state machines.
The point is to encode invariants as nested enums (this variant always contains this family of sub-variants) without paying a readability or ergonomics tax when constructing or matching.
How To Use
use nestum;
Cross-Module Nesting
To nest an enum declared in a different module file, use an external path on the variant:
use nestum;
API Summary
#[nestum] on enums
Enables nested paths and match rewriting.
#[nestum(external = "path::to::Enum")] on variants
Opt-in support for nesting an enum in another module file.
nestum_match! { match value { ... } } / nested! { match value { ... } }
Macro that rewrites nested patterns (like Event::Documents::Update) into real enum patterns.
Limitations
- External crates are not supported (proc macros can’t reliably inspect other crates’ ASTs).
- The macro only resolves enums from source files in the current crate.
#[path = "..."],include!(), and complexcfglayouts may not be resolved.
License
MIT