From 287d45e32b9bdeaaf58b70ebb9a27335f74c529d Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sun, 17 May 2026 22:59:15 +0800 Subject: Add no-return-value mode for `#[chain]` macro --- mingling_macros/src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'mingling_macros/src/lib.rs') diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 85b89a3..760a6ef 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -1138,13 +1138,15 @@ pub fn register_renderer(input: TokenStream) -> TokenStream { /// Internal macro used by `gen_program!` to generate fallback types. /// -/// This macro generates two fallback wrapper types that are essential +/// This macro generates the fallback wrapper types that are essential /// for error handling in the Mingling pipeline: /// /// - **`RendererNotFound`** — Wraps a `String` (the name of the missing renderer). /// Used when no matching renderer is found for a given output type. /// - **`DispatcherNotFound`** — Wraps `Vec` (the unrecognized command args). /// Used when no matching dispatcher is found for user input. +/// - **`EmptyResult`** — Wraps `()` (the unit type). +/// Used when the chain returns an empty result. /// /// Users can (and should) write `#[renderer]` functions for these types /// to provide meaningful error messages. @@ -1165,6 +1167,7 @@ pub fn register_renderer(input: TokenStream) -> TokenStream { /// ```rust,ignore /// pack!(ProgramName, RendererNotFound = String); /// pack!(ProgramName, DispatcherNotFound = Vec); +/// pack!(ProgramName, EmptyResult = ()); /// ``` #[proc_macro] pub fn program_fallback_gen(input: TokenStream) -> TokenStream { @@ -1173,6 +1176,7 @@ pub fn program_fallback_gen(input: TokenStream) -> TokenStream { let expanded = quote! { ::mingling::macros::pack!(#name, RendererNotFound = String); ::mingling::macros::pack!(#name, DispatcherNotFound = Vec); + ::mingling::macros::pack!(#name, EmptyResult = ()); }; TokenStream::from(expanded) } @@ -1213,6 +1217,7 @@ pub fn program_fallback_gen(input: TokenStream) -> TokenStream { /// /// impl ProgramCollect for MyProgram { /// type Enum = MyProgram; +/// type EmptyResult = EmptyResult; /// fn render(any, r) { /* dispatches to all registered renderers */ } /// fn do_chain(any) -> ChainProcess { /* dispatches to all registered chain steps */ } /// fn render_help(any, r) { /* dispatches to all registered help handlers */ } @@ -1386,12 +1391,16 @@ pub fn program_final_gen(input: TokenStream) -> TokenStream { type Enum = #name; type DispatcherNotFound = DispatcherNotFound; type RendererNotFound = RendererNotFound; + type EmptyResult = EmptyResult; fn build_renderer_not_found(member_id: Self::Enum) -> ::mingling::AnyOutput { ::mingling::AnyOutput::new(RendererNotFound::new(member_id.to_string())) } fn build_dispatcher_not_found(args: Vec) -> ::mingling::AnyOutput { ::mingling::AnyOutput::new(DispatcherNotFound::new(args)) } + fn build_empty_result() -> ::mingling::AnyOutput { + ::mingling::AnyOutput::new(EmptyResult::new(())) + } ::mingling::__dispatch_program_renderers!( #(#renderer_tokens)* ); -- cgit