Skip to main content

Crate nestum

Crate nestum 

Source
Expand description

nestum lets real nested enum trees read like their shape.

If your crate already has error envelopes, command trees, or event and message trees, nestum keeps the same nested-enum model and removes most of the wrapping noise around constructors and pattern matches.

use nestum::{nestum, nested};

#[nestum]
enum DocumentEvent {
    Created,
    Deleted,
}

#[nestum]
enum Event {
    Document(DocumentEvent),
}

let event: Event::Enum = Event::Document::Created;

nested! {
    match event {
        Event::Document::Created => {}
        Event::Document::Deleted => {}
    }
}

nestum is worth it when the outer enum is already a real envelope over command, event, message, or error families and the main pain is wrapper syntax, not the model itself.

Main entry points:

  • #[nestum] marks an enum so nested enum-wrapping variants can be constructed through path-shaped syntax.
  • nested! { ... } rewrites nested constructors and nested patterns for match, if let, while let, let-else, matches!, and common assertion macros.
  • #[nestum_scope] rewrites a wider function, impl, method, or inline module body when local nested! wrappers would get noisy.

Authority surface:

  • nestum resolves nesting from parsed crate-local source plus proc-macro source locations.
  • #[cfg], #[cfg_attr], include!(), #[path = "..."], macro-generated local enums, and external crates are outside that surface.
  • unsupported cases are rejected where nestum can detect them, and it errors instead of guessing when source context is unavailable.

For the migration guide, ecosystem cookbooks, and full examples, see the repository README and the nestum-examples workspace crate.

Macros§

nested
nestum_match

Attribute Macros§

nestum
nestum_scope