diff options
Diffstat (limited to 'mingling_macros/src')
| -rw-r--r-- | mingling_macros/src/lib.rs | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 760a6ef..badb117 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -8,7 +8,7 @@ //! The Mingling macros crate provides the following categories of macros: //! //! - **Command definition**: `dispatcher!`, `dispatcher_clap!`, `node!`, `pack!` -//! - **Chain processing**: `#[chain]`, `gen_program!`, `route!` +//! - **Chain processing**: `#[chain]`, `gen_program!`, `route!`, `empty_result!` //! - **Rendering**: `#[renderer]`, `r_print!`, `r_println!` //! - **Help system**: `#[help]`, `register_help!` //! - **Derive macros**: `#[derive(Groupped)]`, `#[derive(EnumTag)]`, `#[derive(GrouppedSerialize)]` @@ -237,6 +237,51 @@ pub fn route(input: TokenStream) -> TokenStream { TokenStream::from(expanded) } +/// Creates an empty result value wrapped in `ChainProcess` for early return +/// from a chain function. +/// +/// This macro is a shorthand for constructing an `EmptyResult` and converting +/// it into a `ChainProcess`, which signals to the pipeline that there is +/// no meaningful output to continue processing. +/// +/// # Syntax +/// +/// ```rust,ignore +/// empty_result!() +/// ``` +/// +/// # Example +/// +/// ```rust,ignore +/// use mingling::macros::{chain, empty_result}; +/// +/// #[chain] +/// fn maybe_skip(prev: SomeEntry) -> Next { +/// if should_skip() { +/// return empty_result!(); +/// } +/// // ... continue processing +/// NextEntry::new(result).to_chain() +/// } +/// ``` +/// +/// # Generated code +/// +/// The macro expands to: +/// ```rust,ignore +/// crate::EmptyResult::new(()).to_chain() +/// ``` +/// +/// This works because `EmptyResult` is automatically generated by `gen_program!` +/// and implements the necessary trait conversions into `ChainProcess`. +#[proc_macro] +pub fn empty_result(_input: TokenStream) -> TokenStream { + let expanded = quote! { + crate::EmptyResult::new(()).to_chain() + }; + TokenStream::from(expanded) +} + /// Creates a `Dispatcher` implementation for a subcommand. /// /// This is the primary way to define command-line subcommands in Mingling. |
