From 6980fbf2f9fb4c599d8dc6ff549a8b3288eb24e9 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 17 Aug 2026 02:29:30 +0800 Subject: refactor!: remove dynamic dispatcher registration API Dispatchers are now always registered at compile time, removing the `with_dispatcher` / `with_dispatchers` methods and the `PathfinderConfig` API. The `dispatch_tree` feature now only controls the matching strategy (trie vs linear list). --- mingling_core/src/program/exec.rs | 80 ++------------------------------------- 1 file changed, 3 insertions(+), 77 deletions(-) (limited to 'mingling_core/src/program/exec.rs') diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index 3ad5ba8..4980d40 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -3,7 +3,7 @@ #![allow(clippy::too_many_lines)] use crate::{ - AnyOutput, ChainProcess, Dispatcher, NextProcess, Program, ProgramCollect, RenderResult, + AnyOutput, ChainProcess, NextProcess, Program, ProgramCollect, RenderResult, error::ProgramInternalExecuteError, hook::ProgramControls, }; @@ -58,12 +58,8 @@ where current ); - // Dispatch args - either via dynamic dispatch or trie dispatch based on feature flag - let mut current = if cfg!(not(feature = "dispatch_tree")) { - dispatch_args_dynamic(program, args)? - } else { - C::dispatch_args(args)? - }; + // Dispatch args + let mut current = C::dispatch_args(args)?; // Run hook control!( @@ -180,76 +176,6 @@ where Ok(render_result) } -/// Dynamically dispatch input arguments to registered entry types -pub(crate) fn dispatch_args_dynamic( - program: &'static Program, - args: &[String], -) -> Result, ProgramInternalExecuteError> -where - C: ProgramCollect, -{ - let next = match match_user_input(program, args) { - Ok((dispatcher, args)) => { - // Entry point - match dispatcher.begin(args) { - ChainProcess::Ok((any, _)) => any, - ChainProcess::Err(e) => return Err(e.into()), - } - } - Err(ProgramInternalExecuteError::DispatcherNotFound) => { - // No matching Dispatcher is found - C::build_entry_fallback(args.to_vec()) - } - Err(e) => return Err(e), - }; - Ok(next) -} - -/// Match user input against registered dispatchers and return the matched dispatcher and remaining arguments. -#[allow(clippy::type_complexity)] -pub(crate) fn match_user_input( - program: &'static Program, - args: &[String], -) -> Result<(&'static (dyn Dispatcher + Send + Sync), Vec), ProgramInternalExecuteError> -where - C: ProgramCollect, -{ - let nodes = program.get_nodes(); - let command = format!("{} ", args.join(" ")); - - // Find all nodes that match the command prefix - let matching_nodes: Vec<&(String, &(dyn Dispatcher + Send + Sync))> = nodes - .iter() - // Also add a space to the node string to ensure consistent matching logic - .filter(|(node_str, _)| command.starts_with(&format!("{node_str} "))) - .collect(); - - match matching_nodes.len() { - 0 => { - // No matching node found - Err(ProgramInternalExecuteError::DispatcherNotFound) - } - 1 => { - let matched_prefix = matching_nodes[0]; - let prefix_len = matched_prefix.0.split_whitespace().count(); - let trimmed_args: Vec = args.iter().skip(prefix_len).cloned().collect(); - Ok((matched_prefix.1, trimmed_args)) - } - _ => { - // Multiple matching nodes found - // Find the node with the longest length (most specific match) - let matched_prefix = matching_nodes - .iter() - .max_by_key(|node| node.0.len()) - .unwrap(); - - let prefix_len = matched_prefix.0.split_whitespace().count(); - let trimmed_args: Vec = args.iter().skip(prefix_len).cloned().collect(); - Ok((matched_prefix.1, trimmed_args)) - } - } -} - #[inline] pub(crate) fn handle_program_control>( program: &Program, -- cgit