aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-20 04:57:57 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-20 04:57:57 +0800
commit34c4c66c1d336469e71fad8cff4828cf5d2bdafb (patch)
tree056dd2aef3b775f0d505353a50eefe9e72b7d84d
parent8526d32f5713caee52a4839701fe4c4e499fc646 (diff)
feat(core)!: remove `to_chain` and `to_render` from `Grouped` trait
Move routing methods exclusively to the `Routable` trait and update all macro-generated code to reference `Routable` instead of `Grouped`
-rw-r--r--CHANGELOG.md19
-rw-r--r--mingling/src/lib.rs5
-rw-r--r--mingling_core/src/any/group.rs24
-rw-r--r--mingling_macros/src/attr/chain.rs4
-rw-r--r--mingling_macros/src/attr/dispatcher_clap.rs10
-rw-r--r--mingling_macros/src/func/gen_program.rs4
-rw-r--r--mingling_macros/src/lib.rs2
-rw-r--r--mling/src/cli.rs2
-rw-r--r--mling/src/proj_mgr/generator.rs2
-rw-r--r--mling/src/proj_mgr/show_binaries.rs2
-rw-r--r--mling/src/proj_mgr/show_directories.rs2
11 files changed, 39 insertions, 37 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54cffcf..766090a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -325,6 +325,25 @@ None
This is a pure rename — no behavioral changes. All functionality remains identical. Downstream code using the old `Groupped` name must migrate to `Grouped`.
+5. **[`core`]** **[`macros`]** Removed `to_chain()` and `to_render()` default methods from the `Grouped` trait. These methods are now exclusively provided by the `Routable` trait. All code that previously called `to_chain()` or `to_render()` via `Grouped` must now call them via `Routable`:
+
+ ```rust
+ // Before (via Grouped — removed)
+ use mingling::Grouped;
+ my_value.to_chain();
+
+ // After (via Routable)
+ use mingling::Routable;
+ my_value.to_chain();
+ ```
+
+ - The `Routable` trait is re-exported in `mingling::prelude` alongside `Grouped`.
+ - The blanket implementation `impl<T: Grouped<C> + Send> Routable<C> for T` remains, so all types that implement `Grouped` still have `to_chain()` and `to_render()` — they just need to import `Routable` instead of relying on `Grouped` for those methods.
+ - Internal macro-generated code (in `#[chain]`, `#[renderer]`, `#[dispatcher_clap]`, `gen_program!`, `empty_result!`, etc.) has been updated to reference `::mingling::Routable::<C>::to_chain(...)` / `::mingling::Routable::<C>::to_render(...)` instead of `::mingling::Grouped::<C>::to_chain(...)` / `::mingling::Grouped::<C>::to_render(...)`.
+ - Downstream crates using `mingling` macros are automatically migrated — the macro output now references `Routable`. Only manual `.to_chain()` / `.to_render()` calls in user code need updating (add `use mingling::Routable;`).
+
+ _No behavioral changes — this is a pure API migration from `Grouped` to `Routable` for routing methods._
+
---
## Release 0.2.2 (2026-07-10)
diff --git a/mingling/src/lib.rs b/mingling/src/lib.rs
index 5cd53db..a34452d 100644
--- a/mingling/src/lib.rs
+++ b/mingling/src/lib.rs
@@ -175,12 +175,15 @@ pub mod res;
/// use mingling::prelude::*;
/// ```
pub mod prelude {
- /// Re-export of the `Grouped` derive macro for grouping types.
+ /// Re-export of the `Grouped` trait
#[cfg(feature = "core")]
pub use crate::Grouped;
/// Re-export of the `RenderResult` struct for outputting rendering result
#[cfg(feature = "core")]
pub use crate::RenderResult;
+ /// Re-export of the `Routable` trait
+ #[cfg(feature = "core")]
+ pub use crate::Routable;
/// Re-export of the `chain` macro for defining a chain of commands.
#[cfg(feature = "macros")]
pub use crate::macros::chain;
diff --git a/mingling_core/src/any/group.rs b/mingling_core/src/any/group.rs
index 90ef9fc..2813ad5 100644
--- a/mingling_core/src/any/group.rs
+++ b/mingling_core/src/any/group.rs
@@ -11,26 +11,6 @@ where
{
/// 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>
- where
- Self: Send,
- {
- 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>
- where
- Self: Send,
- {
- AnyOutput::new(self).route_renderer()
- }
}
impl<T, C> Routable<C> for T
@@ -39,10 +19,10 @@ where
T: Grouped<C> + Send,
{
fn to_chain(self) -> ChainProcess<C> {
- T::to_chain(self)
+ AnyOutput::new(self).route_chain()
}
fn to_render(self) -> ChainProcess<C> {
- T::to_render(self)
+ AnyOutput::new(self).route_renderer()
}
}
diff --git a/mingling_macros/src/attr/chain.rs b/mingling_macros/src/attr/chain.rs
index 120e65d..26bb137 100644
--- a/mingling_macros/src/attr/chain.rs
+++ b/mingling_macros/src/attr/chain.rs
@@ -62,13 +62,13 @@ fn generate_proc_fn(
quote! {
#(#immut_resource_stmts)*
#wrapped_body;
- <crate::ResultEmpty as ::mingling::Grouped::<crate::ThisProgram>>
+ <crate::ResultEmpty as ::mingling::Routable::<crate::ThisProgram>>
::to_chain(crate::ResultEmpty)
}
} else {
quote! {
#wrapped_body;
- <crate::ResultEmpty as ::mingling::Grouped::<crate::ThisProgram>>
+ <crate::ResultEmpty as ::mingling::Routable::<crate::ThisProgram>>
::to_chain(crate::ResultEmpty)
}
};
diff --git a/mingling_macros/src/attr/dispatcher_clap.rs b/mingling_macros/src/attr/dispatcher_clap.rs
index 6083a52..40f7d47 100644
--- a/mingling_macros/src/attr/dispatcher_clap.rs
+++ b/mingling_macros/src/attr/dispatcher_clap.rs
@@ -108,23 +108,23 @@ pub(crate) fn dispatcher_clap_attr(attr: TokenStream, item: TokenStream) -> Toke
let begin_body = if let Some(ref error_struct) = options.error_struct {
quote! {
if ::mingling::this::<#program_path>().user_context.help {
- return #struct_name::default().to_chain();
+ return ::mingling::Routable::<#program_path>::to_chain(#struct_name::default());
}
match <#struct_name as ::clap::Parser>::try_parse_from(clap_args) {
- Ok(parsed) => parsed.to_chain(),
+ Ok(parsed) => ::mingling::Routable::<#program_path>::to_chain(parsed),
Err(e) => {
- return #error_struct::new(format!("{}", e.render().ansi())).to_render()
+ return ::mingling::Routable::<#program_path>::to_render(#error_struct::new(format!("{}", e.render().ansi())))
},
}
}
} else {
quote! {
if ::mingling::this::<#program_path>().user_context.help {
- return #struct_name::default().to_chain();
+ return ::mingling::Routable::<#program_path>::to_chain(#struct_name::default());
}
let parsed = <#struct_name as ::clap::Parser>::try_parse_from(clap_args)
.unwrap_or_else(|e| e.exit());
- parsed.to_chain()
+ ::mingling::Routable::<#program_path>::to_chain(parsed)
}
};
diff --git a/mingling_macros/src/func/gen_program.rs b/mingling_macros/src/func/gen_program.rs
index 7128a9a..a635168 100644
--- a/mingling_macros/src/func/gen_program.rs
+++ b/mingling_macros/src/func/gen_program.rs
@@ -138,7 +138,7 @@ pub(crate) fn program_comp_gen_impl(_input: TokenStream) -> TokenStream {
match read_ctx {
Ok(ctx) => {
let suggest = ::mingling::CompletionHelper::exec_completion::<crate::ThisProgram>(&ctx);
- crate::CompletionSuggest::new((ctx, suggest)).to_render()
+ ::mingling::Routable::<crate::ThisProgram>::to_render(crate::CompletionSuggest::new((ctx, suggest)))
}
Err(_) => std::process::exit(1),
}
@@ -156,7 +156,7 @@ pub(crate) fn program_comp_gen_impl(_input: TokenStream) -> TokenStream {
match read_ctx {
Ok(ctx) => {
let suggest = ::mingling::CompletionHelper::exec_completion::<crate::ThisProgram>(&ctx);
- crate::CompletionSuggest::new((ctx, suggest)).to_render()
+ ::mingling::Routable::<crate::ThisProgram>::to_render(crate::CompletionSuggest::new((ctx, suggest)))
}
Err(_) => std::process::exit(1),
}
diff --git a/mingling_macros/src/lib.rs b/mingling_macros/src/lib.rs
index be355cd..462c6dd 100644
--- a/mingling_macros/src/lib.rs
+++ b/mingling_macros/src/lib.rs
@@ -610,7 +610,7 @@ pub fn route(input: TokenStream) -> TokenStream {
#[proc_macro]
pub fn empty_result(_input: TokenStream) -> TokenStream {
let expanded = quote! {
- <crate::ResultEmpty as ::mingling::Grouped::<crate::ThisProgram>>::to_chain(crate::ResultEmpty)
+ <crate::ResultEmpty as ::mingling::Routable::<crate::ThisProgram>>::to_chain(crate::ResultEmpty)
};
TokenStream::from(expanded)
}
diff --git a/mling/src/cli.rs b/mling/src/cli.rs
index 69e4fe9..20906c0 100644
--- a/mling/src/cli.rs
+++ b/mling/src/cli.rs
@@ -11,7 +11,7 @@ use crate::{
};
use colored::Colorize;
use mingling::{
- Grouped, Program, RenderResult,
+ Grouped, Program, RenderResult, Routable,
hook::ProgramHook,
macros::{chain, help, pack, program_setup, renderer},
res::ResExitCode,
diff --git a/mling/src/proj_mgr/generator.rs b/mling/src/proj_mgr/generator.rs
index f0dbdd7..f1a6345 100644
--- a/mling/src/proj_mgr/generator.rs
+++ b/mling/src/proj_mgr/generator.rs
@@ -1,7 +1,7 @@
use std::path::{self, PathBuf};
use mingling::{
- Grouped, RenderResult,
+ RenderResult, Routable,
macros::{chain, pack, renderer, route},
};
use std::io::Write as _;
diff --git a/mling/src/proj_mgr/show_binaries.rs b/mling/src/proj_mgr/show_binaries.rs
index 4fb5c28..b08c1c3 100644
--- a/mling/src/proj_mgr/show_binaries.rs
+++ b/mling/src/proj_mgr/show_binaries.rs
@@ -2,7 +2,7 @@ use std::path::PathBuf;
use colored::Colorize;
use mingling::{
- Grouped, RenderResult,
+ Grouped, RenderResult, Routable,
macros::{chain, pack, renderer},
};
use serde::Serialize;
diff --git a/mling/src/proj_mgr/show_directories.rs b/mling/src/proj_mgr/show_directories.rs
index 5c5f448..d3c0115 100644
--- a/mling/src/proj_mgr/show_directories.rs
+++ b/mling/src/proj_mgr/show_directories.rs
@@ -1,6 +1,6 @@
use colored::Colorize;
use mingling::{
- Grouped, RenderResult,
+ Grouped, RenderResult, Routable,
macros::{chain, pack, renderer},
};
use serde::Serialize;