From a9d5943939261e27e58bcf5cacbb618a0f63e999 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Mon, 10 Aug 2026 15:49:31 +0800 Subject: 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 --- mingling_core/src/program/exec/error.rs | 48 +++++++++++++-------------------- 1 file changed, 19 insertions(+), 29 deletions(-) (limited to 'mingling_core/src/program/exec') diff --git a/mingling_core/src/program/exec/error.rs b/mingling_core/src/program/exec/error.rs index 944e89a..c8cb15a 100644 --- a/mingling_core/src/program/exec/error.rs +++ b/mingling_core/src/program/exec/error.rs @@ -24,12 +24,12 @@ pub enum ProgramExecuteError { impl fmt::Display for ProgramExecuteError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ProgramExecuteError::DispatcherNotFound => write!(f, "No Dispatcher Found"), - ProgramExecuteError::RendererNotFound(s) => { + Self::DispatcherNotFound => write!(f, "No Dispatcher Found"), + Self::RendererNotFound(s) => { write!(f, "No Renderer (`{s}`) Found") } - ProgramExecuteError::Panic(p) => write!(f, "Panic: {p:?}"), - ProgramExecuteError::Other(s) => write!(f, "Other error: {s}"), + Self::Panic(p) => write!(f, "Panic: {p:?}"), + Self::Other(s) => write!(f, "Other error: {s}"), } } } @@ -38,7 +38,7 @@ impl std::error::Error for ProgramExecuteError {} impl From for ProgramExecuteError { fn from(value: ProgramPanic) -> Self { - ProgramExecuteError::Panic(value) + Self::Panic(value) } } @@ -70,17 +70,11 @@ pub enum ProgramInternalExecuteError { impl fmt::Display for ProgramInternalExecuteError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - ProgramInternalExecuteError::DispatcherNotFound => { - write!(f, "No Dispatcher Found") - } - ProgramInternalExecuteError::RendererNotFound(s) => { - write!(f, "No Renderer (`{s}`) Found") - } - ProgramInternalExecuteError::Other(s) => write!(f, "Other error: {s}"), - ProgramInternalExecuteError::IO(e) => write!(f, "IO error: {e}"), - ProgramInternalExecuteError::REPLPanic(panic) => { - write!(f, "A single REPL execution failed: {panic}") - } + Self::DispatcherNotFound => write!(f, "No Dispatcher Found"), + Self::RendererNotFound(s) => write!(f, "No Renderer (`{s}`) Found"), + Self::Other(s) => write!(f, "Other error: {s}"), + Self::IO(e) => write!(f, "IO error: {e}"), + Self::REPLPanic(panic) => write!(f, "A single REPL execution failed: {panic}"), } } } @@ -88,7 +82,7 @@ impl fmt::Display for ProgramInternalExecuteError { impl std::error::Error for ProgramInternalExecuteError { fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { match self { - ProgramInternalExecuteError::IO(e) => Some(e), + Self::IO(e) => Some(e), _ => None, } } @@ -96,23 +90,19 @@ impl std::error::Error for ProgramInternalExecuteError { impl From for ProgramInternalExecuteError { fn from(e: std::io::Error) -> Self { - ProgramInternalExecuteError::IO(e) + Self::IO(e) } } impl From for ProgramExecuteError { fn from(value: ProgramInternalExecuteError) -> Self { match value { - ProgramInternalExecuteError::DispatcherNotFound => { - ProgramExecuteError::DispatcherNotFound - } - ProgramInternalExecuteError::RendererNotFound(s) => { - ProgramExecuteError::RendererNotFound(s) - } - ProgramInternalExecuteError::Other(s) => ProgramExecuteError::Other(s), - ProgramInternalExecuteError::IO(e) => ProgramExecuteError::Other(format!("{e}")), + ProgramInternalExecuteError::DispatcherNotFound => Self::DispatcherNotFound, + ProgramInternalExecuteError::RendererNotFound(s) => Self::RendererNotFound(s), + ProgramInternalExecuteError::Other(s) => Self::Other(s), + ProgramInternalExecuteError::IO(e) => Self::Other(format!("{e}")), ProgramInternalExecuteError::REPLPanic(p) => { - ProgramExecuteError::Other(format!("A single REPL execution failed: {p}")) + Self::Other(format!("A single REPL execution failed: {p}")) } } } @@ -121,8 +111,8 @@ impl From for ProgramExecuteError { impl From for ProgramInternalExecuteError { fn from(value: ChainProcessError) -> Self { match value { - ChainProcessError::Other(s) => ProgramInternalExecuteError::Other(s), - ChainProcessError::IO(error) => ProgramInternalExecuteError::IO(error), + ChainProcessError::Other(s) => Self::Other(s), + ChainProcessError::IO(error) => Self::IO(error), } } } -- cgit