aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/lib.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-06-27 17:46:29 +0800
committer魏曹先生 <1992414357@qq.com>2026-06-27 17:46:29 +0800
commit4f7bd4f6fa5d27cfe703c54aa029a321f40d19fb (patch)
tree97c31ddbb905d8f0e70418b0970ee6420aeac611 /mingling_macros/src/lib.rs
parent6cadc8d39adebbc263e8576c389b5ef491f10ace (diff)
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.
Diffstat (limited to 'mingling_macros/src/lib.rs')
-rw-r--r--mingling_macros/src/lib.rs18
1 files changed, 16 insertions, 2 deletions
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).