From 2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Sun, 31 May 2026 02:42:52 +0800 Subject: Enhance code quality across the entire codebase --- mingling_core/src/program/exec.rs | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 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 72a20b9..0cadc6a 100644 --- a/mingling_core/src/program/exec.rs +++ b/mingling_core/src/program/exec.rs @@ -15,8 +15,7 @@ pub async fn exec( where C: ProgramCollect, { - let args = program.args.clone(); - exec_with_args(program, args).await + exec_with_args(program, &program.args).await } #[cfg(not(feature = "async"))] @@ -24,26 +23,25 @@ pub fn exec(program: &'static Program) -> Result, { - let args = program.args.clone(); - exec_with_args(program, args) + exec_with_args(program, &program.args) } #[cfg(feature = "async")] pub async fn exec_with_args( program: &'static Program, - args: Vec, + args: &[String], ) -> Result where C: ProgramCollect, { // Run hooks - program.run_hook_pre_dispatch(&args); + program.run_hook_pre_dispatch(args); #[cfg(not(feature = "dispatch_tree"))] - let mut current = dispatch_args_dynamic(program, &args)?; + let mut current = dispatch_args_dynamic(program, args)?; #[cfg(feature = "dispatch_tree")] - let mut current = C::dispatch_args_trie(&args)?; + let mut current = C::dispatch_args_trie(args)?; // Run hook program.run_hook_post_dispatch(¤t.member_id); @@ -125,19 +123,19 @@ where #[cfg(not(feature = "async"))] pub fn exec_with_args( program: &'static Program, - args: Vec, + args: &[String], ) -> Result where C: ProgramCollect, { // Run hooks - program.run_hook_pre_dispatch(&args); + program.run_hook_pre_dispatch(args); #[cfg(not(feature = "dispatch_tree"))] - let mut current = dispatch_args_dynamic(program, &args)?; + let mut current = dispatch_args_dynamic(program, args)?; #[cfg(feature = "dispatch_tree")] - let mut current = C::dispatch_args_trie(&args)?; + let mut current = C::dispatch_args_trie(args)?; // Run hook program.run_hook_post_dispatch(¤t.member_id); @@ -221,7 +219,7 @@ where /// Dynamically dispatch input arguments to registered entry types pub(crate) fn dispatch_args_dynamic( program: &'static Program, - args: &Vec, + args: &[String], ) -> Result, ProgramInternalExecuteError> where C: ProgramCollect, @@ -236,7 +234,7 @@ where } Err(ProgramInternalExecuteError::DispatcherNotFound) => { // No matching Dispatcher is found - C::build_dispatcher_not_found(args.clone()) + C::build_dispatcher_not_found(args.to_vec()) } Err(e) => return Err(e), }; @@ -245,10 +243,9 @@ where /// Match user input against registered dispatchers and return the matched dispatcher and remaining arguments. #[allow(clippy::type_complexity)] -#[allow(clippy::ptr_arg)] pub(crate) fn match_user_input( program: &'static Program, - args: &Vec, + args: &[String], ) -> Result<(&'static (dyn Dispatcher + Send + Sync), Vec), ProgramInternalExecuteError> where C: ProgramCollect, @@ -260,7 +257,7 @@ where 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))) + .filter(|(node_str, _)| command.starts_with(&format!("{node_str} "))) .collect(); match matching_nodes.len() { @@ -289,7 +286,7 @@ where } } -#[inline(always)] +#[inline] #[allow(unused_variables)] fn render>(program: &Program, any: AnyOutput) -> RenderResult { #[cfg(not(feature = "general_renderer"))] @@ -312,7 +309,7 @@ fn render>(program: &Program, any: AnyOutput) } } -#[inline(always)] +#[inline] #[allow(unused_variables)] fn render_help>( program: &Program, -- cgit