diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-20 00:17:21 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-20 00:17:21 +0800 |
| commit | e1b8f6bc80c361070265484fcc442f7923523c1e (patch) | |
| tree | c0cb7333f302634d308ee79d1512e0f9679b9ebb | |
| parent | 4be889ac2dc5263ce03bb014de24916bee2e9aa8 (diff) | |
Move to_chain and to_render to Groupped trait
| -rw-r--r-- | CHANGELOG.md | 22 | ||||
| -rw-r--r-- | mingling_core/src/any/group.rs | 16 | ||||
| -rw-r--r-- | mingling_macros/src/groupped.rs | 12 | ||||
| -rw-r--r-- | mingling_macros/src/pack.rs | 24 |
4 files changed, 38 insertions, 36 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 4dc1aa9..9875171 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -195,6 +195,28 @@ use mingling::{res::ExitCode, REPL}; use mingling::{res::ResExitCode, res::ResREPL}; ``` +3. **\[core\]** **\[macros\]** Migrated `to_chain()` and `to_render()` methods from being generated individually per type by `#[derive(Groupped)]` and `pack!` macros, to being provided as default trait methods on the `Groupped` trait itself. + + Previously, each packed or derived type had its own inherent `to_chain()` and `to_render()` methods generated by the macros. Now, these methods are defined on the `Groupped<Group>` trait with default implementations, making them available to all types that implement the trait without redundant code generation. + + ```rust + // Before (generated per type by macros): + impl MyType { + pub fn to_chain(self) -> ChainProcess<Group> { + AnyOutput::new(self).route_chain() + } + pub fn to_render(self) -> ChainProcess<Group> { + AnyOutput::new(self).route_renderer() + } + } + + // After (provided by Groupped trait default methods): + // just ensure Groupped is implemented — to_chain() and to_render() + // are automatically available + ``` + + Removed the per-type inherent method generation from both `groupped.rs` and `pack.rs` in `mingling_macros`. + ### Release 0.1.9 (2026-05-29) #### Fixes: diff --git a/mingling_core/src/any/group.rs b/mingling_core/src/any/group.rs index 04701f2..c251286 100644 --- a/mingling_core/src/any/group.rs +++ b/mingling_core/src/any/group.rs @@ -1,5 +1,21 @@ +use crate::{AnyOutput, ChainProcess}; + /// Used to mark a type with a unique enum ID, assisting dynamic dispatch pub trait Groupped<Group> { /// Returns the specific enum value representing its ID within that enum fn member_id() -> Group; + + /// Converts the grouped item into a `ChainProcess` directed to the chain route. + /// + /// This wraps the item into an `AnyOutput` and routes it to the chain processing pipeline. + fn to_chain(self) -> ChainProcess<Group> { + AnyOutput::new(self).route_chain() + } + + /// Converts the grouped item into a `ChainProcess` directed to the render route. + /// + /// This wraps the item into an `AnyOutput` and routes it to the render processing pipeline. + fn to_render(self) -> ChainProcess<Group> { + AnyOutput::new(self).route_renderer() + } } diff --git a/mingling_macros/src/groupped.rs b/mingling_macros/src/groupped.rs index 534e2a6..03f0b9c 100644 --- a/mingling_macros/src/groupped.rs +++ b/mingling_macros/src/groupped.rs @@ -92,18 +92,6 @@ fn build_any_output_convert_impls( ::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() } diff --git a/mingling_macros/src/pack.rs b/mingling_macros/src/pack.rs index 5a1c388..bf2536d 100644 --- a/mingling_macros/src/pack.rs +++ b/mingling_macros/src/pack.rs @@ -187,18 +187,6 @@ pub fn pack(input: TokenStream) -> TokenStream { mingling::AnyOutput::new(self).route_chain() } } - - impl #type_name { - /// Converts the wrapper type into a `ChainProcess` for chaining operations. - pub fn to_chain(self) -> mingling::ChainProcess<#group_name> { - mingling::AnyOutput::new(self).route_chain() - } - - /// Converts the wrapper type into a `ChainProcess` for rendering operations. - pub fn to_render(self) -> mingling::ChainProcess<#group_name> { - mingling::AnyOutput::new(self).route_renderer() - } - } }; let group_impl = quote! { @@ -234,18 +222,6 @@ pub fn pack(input: TokenStream) -> TokenStream { } } - impl #type_name { - /// Converts the wrapper type into a `ChainProcess` for chaining operations. - pub fn to_chain(self) -> mingling::ChainProcess<#group_name> { - mingling::AnyOutput::new(self).route_chain() - } - - /// Converts the wrapper type into a `ChainProcess` for rendering operations. - pub fn to_render(self) -> mingling::ChainProcess<#group_name> { - mingling::AnyOutput::new(self).route_renderer() - } - } - impl ::mingling::Groupped<#group_name> for #type_name { fn member_id() -> #group_name { #group_name::#type_name |
