From 7adbe2715285d7baedfb91f5e81f5ea64f7d1a5a Mon Sep 17 00:00:00 2001
From: Weicao-CatilGrass <1992414357@qq.com>
Date: Fri, 22 May 2026 08:33:46 +0800
Subject: Extract resource injection into shared module and add to #[renderer]
---
mingling_macros/src/renderer.rs | 132 ++++++++++++++++++++++------------------
1 file changed, 72 insertions(+), 60 deletions(-)
(limited to 'mingling_macros/src/renderer.rs')
diff --git a/mingling_macros/src/renderer.rs b/mingling_macros/src/renderer.rs
index 39ea594..db04c19 100644
--- a/mingling_macros/src/renderer.rs
+++ b/mingling_macros/src/renderer.rs
@@ -1,42 +1,12 @@
use proc_macro::TokenStream;
use quote::{ToTokens, quote};
use syn::spanned::Spanned;
-use syn::{FnArg, ItemFn, Pat, PatType, ReturnType, Signature, Type, TypePath, parse_macro_input};
+use syn::{ItemFn, ReturnType, Signature, Type, TypePath, parse_macro_input};
use crate::get_global_set;
-
-/// Extracts the previous type and parameter name from function arguments
-fn extract_previous_info(sig: &Signature) -> syn::Result<(Pat, TypePath)> {
- // The function should have exactly one parameter
- if sig.inputs.len() != 1 {
- return Err(syn::Error::new(
- sig.inputs.span(),
- "Renderer function must have exactly one parameter (the previous type)",
- ));
- }
-
- // First and only parameter is the previous type
- let arg = &sig.inputs[0];
- match arg {
- FnArg::Typed(PatType { pat, ty, .. }) => {
- // Extract the pattern (parameter name)
- let param_pat = (**pat).clone();
-
- // Extract the type
- match &**ty {
- Type::Path(type_path) => Ok((param_pat, type_path.clone())),
- _ => Err(syn::Error::new(
- ty.span(),
- "Parameter type must be a type path",
- )),
- }
- }
- FnArg::Receiver(_) => Err(syn::Error::new(
- arg.span(),
- "Renderer function cannot have self parameter",
- )),
- }
-}
+use crate::res_injection::{
+ extract_args_info, generate_immut_resource_bindings, wrap_body_with_mut_resources,
+};
/// Extracts and returns the return type from the function signature (or None for `()` / no return type).
fn extract_return_type(sig: &Signature) -> syn::Result