aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-04-18 00:38:52 +0800
committer魏曹先生 <1992414357@qq.com>2026-04-18 00:38:52 +0800
commit6e807145b892209f95e70628ee7a3e62bcd9f086 (patch)
tree281bf8cc5c4bf72962bf19e18f5730d1967f8028 /mingling_macros
parent3e40169951350b3a00d2d170fa9a4f7cfb9137df (diff)
Add AnyOutput and ChainProcess conversion impls
Diffstat (limited to 'mingling_macros')
-rw-r--r--mingling_macros/src/groupped.rs43
1 files changed, 43 insertions, 0 deletions
diff --git a/mingling_macros/src/groupped.rs b/mingling_macros/src/groupped.rs
index 032e60b..5e0c3e9 100644
--- a/mingling_macros/src/groupped.rs
+++ b/mingling_macros/src/groupped.rs
@@ -31,6 +31,11 @@ pub fn derive_groupped(input: TokenStream) -> TokenStream {
let group_ident = parse_group_attribute(&input.attrs)
.unwrap_or_else(|| Ident::new("ThisProgram", Span::call_site()));
+ let any_output_convert_impls = proc_macro2::TokenStream::from(build_any_output_convert_impls(
+ struct_name.clone(),
+ group_ident.clone(),
+ ));
+
// Generate the Groupped trait implementation
let expanded = quote! {
impl ::mingling::Groupped<#group_ident> for #struct_name {
@@ -38,6 +43,8 @@ pub fn derive_groupped(input: TokenStream) -> TokenStream {
#group_ident::#struct_name
}
}
+
+ #any_output_convert_impls
};
expanded.into()
@@ -53,6 +60,11 @@ pub fn derive_groupped_serialize(input: TokenStream) -> TokenStream {
let group_ident = parse_group_attribute(&input_parsed.attrs)
.unwrap_or_else(|| Ident::new("ThisProgram", Span::call_site()));
+ let any_output_convert_impls = proc_macro2::TokenStream::from(build_any_output_convert_impls(
+ struct_name.clone(),
+ group_ident.clone(),
+ ));
+
// Generate both Serialize and Groupped implementations
let expanded = quote! {
#[derive(serde::Serialize)]
@@ -63,7 +75,38 @@ pub fn derive_groupped_serialize(input: TokenStream) -> TokenStream {
#group_ident::#struct_name
}
}
+
+ #any_output_convert_impls
};
expanded.into()
}
+
+fn build_any_output_convert_impls(struct_name: Ident, group_ident: Ident) -> TokenStream {
+ quote! {
+ impl ::std::convert::Into<::mingling::AnyOutput<#group_ident>> for #struct_name {
+ fn into(self) -> ::mingling::AnyOutput<#group_ident> {
+ ::mingling::AnyOutput::new(self)
+ }
+ }
+
+ impl ::std::convert::Into<::mingling::ChainProcess<#group_ident>> for #struct_name {
+ fn into(self) -> ::mingling::ChainProcess<#group_ident> {
+ ::mingling::AnyOutput::new(self).route_chain()
+ }
+ }
+
+ impl #struct_name {
+ /// Converts the wrapper type into a `ChainProcess` for chaining operations.
+ pub fn to_chain(self) -> ::mingling::ChainProcess<#group_ident> {
+ ::mingling::AnyOutput::new(self).route_chain()
+ }
+
+ /// Converts the wrapper type into a `ChainProcess` for rendering operations.
+ pub fn to_render(self) -> ::mingling::ChainProcess<#group_ident> {
+ ::mingling::AnyOutput::new(self).route_renderer()
+ }
+ }
+ }
+ .into()
+}