diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-05-31 02:42:52 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-05-31 17:19:20 +0800 |
| commit | 2aa7bda3cb21ce6c052b82e08bcab79a625d04f2 (patch) | |
| tree | f10b89007fc67ca1a948f34abe6869b49296b932 /mingling_core/src/program.rs | |
| parent | 3aa409a55e4f2f0ab41b0949cc06eb13c2da4a43 (diff) | |
Enhance code quality across the entire codebase
Diffstat (limited to 'mingling_core/src/program.rs')
| -rw-r--r-- | mingling_core/src/program.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/mingling_core/src/program.rs b/mingling_core/src/program.rs index 912975d..2e861e4 100644 --- a/mingling_core/src/program.rs +++ b/mingling_core/src/program.rs @@ -70,6 +70,7 @@ where C: ProgramCollect<Enum = C>, { /// Creates a new Program instance, initializing command-line arguments from the environment. + #[must_use] pub fn new() -> Self { #[cfg(not(windows))] return Self::new_with_args(env::args().collect::<Vec<String>>()); @@ -96,8 +97,8 @@ where #[cfg(not(feature = "dispatch_tree"))] dispatcher: Vec::new(), - stdout_setting: Default::default(), - user_context: Default::default(), + stdout_setting: ProgramStdoutSetting::default(), + user_context: ProgramUserContext::default(), #[cfg(feature = "general_renderer")] general_renderer_name: GeneralRendererSetting::Disable, @@ -109,6 +110,10 @@ where } /// Returns a reference to the current program instance, if set. + /// + /// # Panics + /// + /// Panics if the program has not been initialized yet. pub fn this_program() -> &'static Program<C> where C: 'static, @@ -123,6 +128,7 @@ where } /// Get all registered dispatcher names from the program + #[must_use] pub fn get_nodes( &'static self, ) -> Vec<(String, &'static (dyn Dispatcher<C> + Send + Sync + 'static))> { @@ -130,11 +136,17 @@ where } /// Dynamically dispatch input arguments to registered entry types + /// + /// # Errors + /// + /// Returns `Err(ChainProcessError)` if the dispatch fails, + /// e.g., if no dispatcher is found for the given arguments. pub fn dispatch_args_dynamic( &'static self, args: impl Into<StringVec>, ) -> Result<AnyOutput<C>, ChainProcessError> { - match exec::dispatch_args_dynamic(self, &args.into().into()) { + let sv: Vec<String> = args.into().into(); + match exec::dispatch_args_dynamic(self, &sv) { Ok(ok) => Ok(ok), Err(e) => Err(e.into()), } @@ -229,6 +241,7 @@ macro_rules! __dispatch_program_chains { /// Get all registered dispatcher names from the program #[allow(unused_variables)] +#[must_use] pub fn get_nodes<C: ProgramCollect<Enum = C>>( program: &'static Program<C>, ) -> Vec<(String, &'static (dyn Dispatcher<C> + Send + Sync + 'static))> { |
