diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-05-07 20:53:04 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-07 21:15:54 +0800 |
| commit | 6703ccb0fc3aca7ba4bdb9083f199fe0c1b66bd9 (patch) | |
| tree | 9cc0ea01bd42886cee93747068388076dd1d06f6 /mingling_core/src/program/exec.rs | |
| parent | dd5fbe024003f9d76ba0e063ade6b60dee2ffaa8 (diff) | |
Add dispatch tree feature for fast argument matching
Diffstat (limited to 'mingling_core/src/program/exec.rs')
| -rw-r--r-- | mingling_core/src/program/exec.rs | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/mingling_core/src/program/exec.rs b/mingling_core/src/program/exec.rs index 469f6d2..9cb2892 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -9,11 +9,18 @@ use crate::{ pub mod error; #[cfg(feature = "async")] -pub async fn exec<C>(program: &Program<C>) -> Result<RenderResult, ProgramInternalExecuteError> +pub async fn exec<C>( + program: &'static Program<C>, +) -> Result<RenderResult, ProgramInternalExecuteError> where C: ProgramCollect<Enum = C>, { - let mut current = dispatch_args_dynamic(program, program.args.clone())?; + #[cfg(not(feature = "dispatch_tree"))] + let mut current = dispatch_args_dynamic(program, &program.args)?; + + #[cfg(feature = "dispatch_tree")] + let mut current = C::dispatch_args_trie(&program.args)?; + let mut stop_next = false; // If the program has Help enabled, skip actual logic and jump to Help @@ -54,11 +61,16 @@ where } #[cfg(not(feature = "async"))] -pub fn exec<C>(program: &Program<C>) -> Result<RenderResult, ProgramInternalExecuteError> +pub fn exec<C>(program: &'static Program<C>) -> Result<RenderResult, ProgramInternalExecuteError> where C: ProgramCollect<Enum = C>, { - let mut current = dispatch_args_dynamic(program, program.args.clone())?; + #[cfg(not(feature = "dispatch_tree"))] + let mut current = dispatch_args_dynamic(program, &program.args)?; + + #[cfg(feature = "dispatch_tree")] + let mut current = C::dispatch_args_trie(&program.args)?; + let mut stop_next = false; // If the program has Help enabled, skip actual logic and jump to Help @@ -100,8 +112,8 @@ where /// Dynamically dispatch input arguments to registered entry types pub(crate) fn dispatch_args_dynamic<C>( - program: &Program<C>, - args: Vec<String>, + program: &'static Program<C>, + args: &Vec<String>, ) -> Result<AnyOutput<C>, ProgramInternalExecuteError> where C: ProgramCollect<Enum = C>, @@ -126,9 +138,9 @@ where /// Match user input against registered dispatchers and return the matched dispatcher and remaining arguments. #[allow(clippy::type_complexity)] pub(crate) fn match_user_input<C>( - program: &Program<C>, - args: Vec<String>, -) -> Result<(&(dyn Dispatcher<C> + Send + Sync), Vec<String>), ProgramInternalExecuteError> + program: &'static Program<C>, + args: &Vec<String>, +) -> Result<(&'static (dyn Dispatcher<C> + Send + Sync), Vec<String>), ProgramInternalExecuteError> where C: ProgramCollect<Enum = C>, { |
