From d94103fd7e76dd86cd64c23f00c818165fb7dc22 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 23 Jun 2026 00:23:00 +0800 Subject: Replace macro_rules dispatch with proc-macro generation Generate `render()` and `do_chain()` match dispatch directly in `program_final_gen`, using a compile-time `ASYNC_ENABLED` constant to select the correct sync/async signature. Removes the `__dispatch_program_renderers!` and `__dispatch_program_chains!` macros from `mingling_core`. --- mingling_core/src/program.rs | 73 -------------------------------------------- 1 file changed, 73 deletions(-) (limited to 'mingling_core/src/program.rs') diff --git a/mingling_core/src/program.rs b/mingling_core/src/program.rs index 12dc9cc..a1b803e 100644 --- a/mingling_core/src/program.rs +++ b/mingling_core/src/program.rs @@ -169,79 +169,6 @@ where } } -#[macro_export] -#[doc(hidden)] -macro_rules! __dispatch_program_renderers { - ( - $( $render_ty:ty => $prev_ty:ident, )* - ) => { - fn render(any: mingling::AnyOutput, __renderer_inner_result: &mut mingling::RenderResult) { - match any.member_id { - $( - Self::$prev_ty => { - // SAFETY: The `type_id` check ensures that `any` contains a value of type `$prev_ty`, - // so downcasting to `$prev_ty` is safe. - let value = unsafe { any.downcast::<$prev_ty>().unwrap_unchecked() }; - <$render_ty as mingling::Renderer>::render(value, __renderer_inner_result); - } - )* - _ => (), - } - } - }; -} - -#[macro_export] -#[doc(hidden)] -#[cfg(feature = "async")] -macro_rules! __dispatch_program_chains { - ( - $( $chain_ty:ty => $chain_prev:ident, )* - ) => { - fn do_chain( - any: mingling::AnyOutput, - ) -> std::pin::Pin> + Send>> { - match any.member_id { - $( - Self::$chain_prev => { - // SAFETY: The `type_id` check ensures that `any` contains a value of type `$chain_prev`, - // so downcasting to `$chain_prev` is safe. - let value = unsafe { any.downcast::<$chain_prev>().unwrap_unchecked() }; - let fut = async { <$chain_ty as mingling::Chain>::proc(value).await }; - Box::pin(fut) - } - )* - _ => panic!("No chain found for type id: {:?}", any.type_id), - } - } - }; -} - -#[macro_export] -#[doc(hidden)] -#[cfg(not(feature = "async"))] -macro_rules! __dispatch_program_chains { - ( - $( $chain_ty:ty => $chain_prev:ident, )* - ) => { - fn do_chain( - any: mingling::AnyOutput, - ) -> mingling::ChainProcess { - match any.member_id { - $( - Self::$chain_prev => { - // SAFETY: The `type_id` check ensures that `any` contains a value of type `$chain_prev`, - // so downcasting to `$chain_prev` is safe. - let value = unsafe { any.downcast::<$chain_prev>().unwrap_unchecked() }; - <$chain_ty as mingling::Chain>::proc(value) - } - )* - _ => panic!("No chain found for type id: {:?}", any.type_id), - } - } - }; -} - /// Get all registered dispatcher names from the program #[allow(unused_variables)] #[must_use] -- cgit