diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-10 15:49:31 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-10 15:49:31 +0800 |
| commit | a9d5943939261e27e58bcf5cacbb618a0f63e999 (patch) | |
| tree | d1cacc2af939e993f2d7d2794500e6456659e6a9 /mingling_core/src/program/repl_exec.rs | |
| parent | 782d2458dc4ad4336e1407e1f107e43e39b0b991 (diff) | |
refactor(core): improve code style and public API clarity
Replace bool-based settings with enums, refine visibility and
signatures, and standardize `Self` usage across the crate.
- Introduce `ErrorOutput`, `RenderOutput`, `PanicSilence`, `Verbosity`,
`ColorOutput`, and `ProgressOutput` enums for clearer configuration
semantics
- Make `GlobalResources`, `ProgramCell`, and
`split_input`/`split_input_string` public
- Change hook info parameters to accept references and
`split_input_string` to take `&str`
- Apply `Self` shorthand throughout implementations and add
`#[must_use]` attributes where appropriate
- Enable strict clippy lints with targeted allowances
Diffstat (limited to 'mingling_core/src/program/repl_exec.rs')
| -rw-r--r-- | mingling_core/src/program/repl_exec.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/mingling_core/src/program/repl_exec.rs b/mingling_core/src/program/repl_exec.rs index f84b291..ea36c75 100644 --- a/mingling_core/src/program/repl_exec.rs +++ b/mingling_core/src/program/repl_exec.rs @@ -29,7 +29,7 @@ where // Inject default REPL resource self.with_resource(ResREPL::default()); - self.run_hook_repl_on_begin(crate::hook::HookREPLBeginInfo {}); + self.run_hook_repl_on_begin(&crate::hook::HookREPLBeginInfo {}); might_be_async::select!( self.exec_wrapper(async |p| -> () { @@ -48,43 +48,43 @@ where C: ProgramCollect<Enum = C> + Send + Sync + 'static, { loop { - p.run_hook_repl_pre_readline(crate::hook::HookREPLPreReadlineInfo {}); + p.run_hook_repl_pre_readline(&crate::hook::HookREPLPreReadlineInfo {}); let mut readline = p - .run_hook_repl_readline(crate::hook::HookREPLReadlineInfo {}) + .run_hook_repl_readline(&crate::hook::HookREPLReadlineInfo {}) .unwrap_or_default(); - p.run_hook_repl_post_readline(crate::hook::HookREPLPostReadlineInfo { + p.run_hook_repl_post_readline(&crate::hook::HookREPLPostReadlineInfo { line: &mut readline, }); - let args = split_input_string(readline.clone()); + let args = split_input_string(&readline); - p.run_hook_repl_pre_exec(crate::hook::HookREPLPreExecInfo { args: &args }); - match might_be_async::invoke!(exec_once(p, args)) { + p.run_hook_repl_pre_exec(&crate::hook::HookREPLPreExecInfo { args: &args }); + match might_be_async::invoke!(exec_once(p, &args)) { Ok(r) => { - p.run_hook_repl_on_receive_result(crate::hook::HookREPLOnReceiveResultInfo { + p.run_hook_repl_on_receive_result(&crate::hook::HookREPLOnReceiveResultInfo { result: &r, }); } Err(ProgramInternalExecuteError::REPLPanic(panic)) => { - p.run_hook_repl_on_panic(crate::hook::HookREPLOnPanicInfo { panic: &panic }); + p.run_hook_repl_on_panic(&crate::hook::HookREPLOnPanicInfo { panic: &panic }); } _ => {} } - p.run_hook_repl_post_exec(crate::hook::HookREPLPostExecInfo {}); + p.run_hook_repl_post_exec(&crate::hook::HookREPLPostExecInfo {}); if this::<C>().res::<ResREPL>().unwrap().exit { - p.run_hook_repl_exit(crate::hook::HookREPLExitInfo {}); + p.run_hook_repl_exit(&crate::hook::HookREPLExitInfo {}); break; } - p.run_hook_repl_loop_once(crate::hook::HookREPLLoopOnceInfo {}); + p.run_hook_repl_loop_once(&crate::hook::HookREPLLoopOnceInfo {}); } } #[cfg(not(feature = "async"))] fn exec_once<C>( p: &'static Program<C>, - args: Vec<String>, + args: &[String], ) -> Result<RenderResult, ProgramInternalExecuteError> where C: ProgramCollect<Enum = C> + Send + Sync + 'static, @@ -95,7 +95,7 @@ where #[cfg(not(panic = "abort"))] let exec_result = { let exec_unwind_result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { - super::exec::exec_with_args(p, &args) + super::exec::exec_with_args(p, args) })); match exec_unwind_result { @@ -108,7 +108,7 @@ where .unwrap() .downcast_ref::<Program<C>>() .unwrap(); - program.run_hook_repl_on_panic(crate::hook::HookREPLOnPanicInfo { + program.run_hook_repl_on_panic(&crate::hook::HookREPLOnPanicInfo { panic: &panic_payload, }); Err(ProgramInternalExecuteError::REPLPanic(panic_payload)) @@ -123,7 +123,7 @@ where #[cfg(feature = "async")] async fn exec_once<C>( p: &'static Program<C>, - args: Vec<String>, + args: &[String], ) -> Result<RenderResult, ProgramInternalExecuteError> where C: ProgramCollect<Enum = C> + Send + Sync + 'static, |
