diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-17 01:35:00 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-17 01:35:00 +0800 |
| commit | 4c191b2b46a67a0dda6e9a867b40f45156af4f9c (patch) | |
| tree | f560f65169dc41aad9a0e27c5f7a969ab1f1d8c1 | |
| parent | 3ff0404be20633d8546758adc05b5075c3227019 (diff) | |
refactor!: rename dispatch_args_trie to dispatch_args
| -rw-r--r-- | CHANGELOG.md | 17 | ||||
| -rw-r--r-- | mingling_core/src/comp.rs | 8 | ||||
| -rw-r--r-- | mingling_core/src/program.rs | 4 | ||||
| -rw-r--r-- | mingling_core/src/program/collection.rs | 4 | ||||
| -rw-r--r-- | mingling_core/src/program/collection/mock.rs | 2 | ||||
| -rw-r--r-- | mingling_core/src/program/exec.rs | 2 | ||||
| -rw-r--r-- | mingling_macros/src/systems/dispatch_tree_gen.rs | 4 |
7 files changed, 28 insertions, 13 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 449e3a5..694ce61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -70,7 +70,22 @@ None #### **BREAKING CHANGES** (API CHANGES): -None +1. **[`core:comp`]** **[`macros:dispatch_tree`]** **[BREAKING RENAME]** Renamed the prefix-tree dispatch method `dispatch_args_trie` to `dispatch_args` across the codebase. + + **Renamed methods:** + + - `ProgramCollect::dispatch_args_trie` → `ProgramCollect::dispatch_args` (trait definition in `mingling_core/src/program/collection.rs`) + - `Program::dispatch_args_trie` → `Program::dispatch_args` (in `mingling_core/src/program.rs`) + - `MockProgramCollect::dispatch_args_trie` → `MockProgramCollect::dispatch_args` (in `mingling_core/src/program/collection/mock.rs`) + - The `dispatch_args_trie` function body generated by `dispatch_tree_gen.rs` now emits a `dispatch_args` method instead. + - All call sites updated: `mingling_core/src/program/exec.rs`, `mingling_macros/src/systems/dispatch_tree_gen.rs`, and two call sites in `mingling_core/src/comp.rs` (both in the `CompletionHelper::complete` method and in the `entry_description` helper's dispatch-tree branch). + + **Migration guide:** + + - Any code calling `C::dispatch_args_trie(...)` or `program.dispatch_args_trie(...)` must now call `C::dispatch_args(...)` or `program.dispatch_args(...)`. + - Any manual `ProgramCollect` implementation (e.g., in tests or mocks) must rename the method from `dispatch_args_trie` to `dispatch_args`. + + _No behavioral changes — this is a pure rename of the prefix-tree dispatch method. The method's semantics, signature, and dispatch-tree behavior are unchanged; only its name dropped the redundant `_trie` suffix. --- diff --git a/mingling_core/src/comp.rs b/mingling_core/src/comp.rs index 4315854..aea46e1 100644 --- a/mingling_core/src/comp.rs +++ b/mingling_core/src/comp.rs @@ -198,8 +198,8 @@ impl CompletionHelper { None }; #[cfg(feature = "dispatch_tree")] - let suggest = if let Ok(any) = P::dispatch_args_trie(&args) { - debug!("dispatch_args_trie OK, member_id = {:?}", any.member_id); + let suggest = if let Ok(any) = P::dispatch_args(&args) { + debug!("dispatch_args OK, member_id = {:?}", any.member_id); trace!("entry type: {}", any.member_id); let entry_fallback = <P::EntryFallback as crate::Grouped<P>>::member_id(); @@ -215,7 +215,7 @@ impl CompletionHelper { Some(result) } } else { - debug!("dispatch_args_trie failed, args = {:?}", args); + debug!("dispatch_args failed, args = {:?}", args); trace!("no dispatcher matched"); None }; @@ -355,7 +355,7 @@ where let words: Vec<String> = node.split(' ').map(str::to_string).collect(); #[cfg(feature = "dispatch_tree")] - let lazy_member = P::dispatch_args_trie(&words).ok().map(|any| any.member_id); + let lazy_member = P::dispatch_args(&words).ok().map(|any| any.member_id); #[cfg(not(feature = "dispatch_tree"))] let lazy_member = match match_user_input(this::<P>(), &words) { diff --git a/mingling_core/src/program.rs b/mingling_core/src/program.rs index 86e3e83..7bafe72 100644 --- a/mingling_core/src/program.rs +++ b/mingling_core/src/program.rs @@ -207,12 +207,12 @@ where /// Use a prefix tree to quickly match arguments and dispatch to an Entry #[cfg(feature = "dispatch_tree")] - pub fn dispatch_args_trie( + pub fn dispatch_args( &'static self, args: impl Into<StringVec>, ) -> Result<AnyOutput<C>, ChainProcessError> { let string_vec: Vec<String> = args.into().into(); - match C::dispatch_args_trie(&string_vec) { + match C::dispatch_args(&string_vec) { Ok(ok) => Ok(ok), Err(e) => Err(e.into()), } diff --git a/mingling_core/src/program/collection.rs b/mingling_core/src/program/collection.rs index 2b3e9ec..438b800 100644 --- a/mingling_core/src/program/collection.rs +++ b/mingling_core/src/program/collection.rs @@ -36,7 +36,7 @@ pub trait ProgramCollect { /// Use a prefix tree to quickly match arguments and dispatch to an Entry #[cfg(feature = "dispatch_tree")] - fn dispatch_args_trie( + fn dispatch_args( raw: &[String], ) -> Result<AnyOutput<Self::Enum>, crate::error::ProgramInternalExecuteError>; @@ -46,7 +46,7 @@ pub trait ProgramCollect { /// # Errors /// /// Returns an error if the program fails to execute the given arguments. - fn dispatch_args_trie( + fn dispatch_args( _raw: &[String], ) -> Result<AnyOutput<Self::Enum>, crate::error::ProgramInternalExecuteError> { unreachable!() diff --git a/mingling_core/src/program/collection/mock.rs b/mingling_core/src/program/collection/mock.rs index 6b4406e..662d8f2 100644 --- a/mingling_core/src/program/collection/mock.rs +++ b/mingling_core/src/program/collection/mock.rs @@ -75,7 +75,7 @@ impl ProgramCollect for MockProgramCollect { type ResultEmpty = Self; #[cfg(feature = "dispatch_tree")] - fn dispatch_args_trie( + fn dispatch_args( _raw: &[String], ) -> Result<AnyOutput<Self::Enum>, crate::error::ProgramInternalExecuteError> { unreachable!() diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index b0a5b16..3ad5ba8 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -62,7 +62,7 @@ where let mut current = if cfg!(not(feature = "dispatch_tree")) { dispatch_args_dynamic(program, args)? } else { - C::dispatch_args_trie(args)? + C::dispatch_args(args)? }; // Run hook diff --git a/mingling_macros/src/systems/dispatch_tree_gen.rs b/mingling_macros/src/systems/dispatch_tree_gen.rs index 989f998..d157feb 100644 --- a/mingling_macros/src/systems/dispatch_tree_gen.rs +++ b/mingling_macros/src/systems/dispatch_tree_gen.rs @@ -30,7 +30,7 @@ pub(crate) fn gen_get_nodes(entries: &[(String, String, String)]) -> TokenStream } } -/// Generate the `dispatch_args_trie()` function body for a ProgramCollect impl. +/// Generate the `dispatch_args()` function body for a ProgramCollect impl. /// /// Builds a hardcoded match tree: at each depth, group nodes by character. /// Single-node groups use `starts_with`; multi-node groups recurse with `nth()` match. @@ -49,7 +49,7 @@ pub(crate) fn gen_dispatch_args_trie(entries: &[(String, String, String)]) -> To ); quote! { - fn dispatch_args_trie( + fn dispatch_args( raw: &[String], ) -> Result<::mingling::AnyOutput<Self::Enum>, ::mingling::error::ProgramInternalExecuteError> { |
