From 4f7bd4f6fa5d27cfe703c54aa029a321f40d19fb Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 27 Jun 2026 17:46:29 +0800 Subject: feat(macros): add async mutable resource injection for `#[chain]` Support `&mut T` resource parameters in async chain functions by using an extract-store pattern that avoids holding mutable borrows across await points. Remove the previous compile-time rejection of this combination. --- mingling_macros/src/lib.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'mingling_macros/src/lib.rs') diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs index 21273ba..1b0cbb5 100644 --- a/mingling_macros/src/lib.rs +++ b/mingling_macros/src/lib.rs @@ -858,8 +858,6 @@ pub fn r_println(input: TokenStream) -> TokenStream { /// - The first parameter (previous type) must be taken **by move**, not by reference. /// - Resource injection parameters **must** be references (`&T` or `&mut T`), /// owned values are not allowed. -/// - When the `async` feature is enabled, `&mut T` cannot be used in async -/// chain functions (only `&T` is supported for async). /// /// # Sync Example /// @@ -924,6 +922,22 @@ pub fn r_println(input: TokenStream) -> TokenStream { /// } /// ``` /// +/// # Async Example with Mutable Resource Injection +/// +/// ```rust,ignore +/// use mingling::macros::{chain, pack, gen_program}; +/// +/// pack!(MyOutput = String); +/// +/// #[chain] +/// async fn greet(prev: HelloEntry, ec: &mut ResExitCode) -> Next { +/// let name = prev.first().cloned().unwrap_or_else(|| "World".to_string()); +/// ec.exit_code = 42; +/// some_async_fn(&name).await; +/// MyOutput::new(name) +/// } +/// ``` +/// /// # Requirements /// /// - The function must have at least **one** parameter (the previous type in the chain). -- cgit