aboutsummaryrefslogtreecommitdiff
path: root/mingling_core/src/program/hook
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-08-10 15:49:31 +0800
committer魏曹先生 <1992414357@qq.com>2026-08-10 15:49:31 +0800
commita9d5943939261e27e58bcf5cacbb618a0f63e999 (patch)
treed1cacc2af939e993f2d7d2794500e6456659e6a9 /mingling_core/src/program/hook
parent782d2458dc4ad4336e1407e1f107e43e39b0b991 (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/hook')
-rw-r--r--mingling_core/src/program/hook/control_unit.rs35
1 files changed, 22 insertions, 13 deletions
diff --git a/mingling_core/src/program/hook/control_unit.rs b/mingling_core/src/program/hook/control_unit.rs
index 5bf0e8c..d71a203 100644
--- a/mingling_core/src/program/hook/control_unit.rs
+++ b/mingling_core/src/program/hook/control_unit.rs
@@ -22,8 +22,8 @@ where
C: ProgramCollect<Enum = C>,
{
/// Returns `true` if the collection is empty.
- pub fn is_empty(&self) -> bool {
- matches!(self, ProgramControls::Empty)
+ pub const fn is_empty(&self) -> bool {
+ matches!(self, Self::Empty)
}
}
@@ -31,7 +31,7 @@ impl<C> From<()> for ProgramControls<C>
where
C: ProgramCollect<Enum = C>,
{
- fn from(_: ()) -> Self {
+ fn from((): ()) -> Self {
Self::Empty
}
}
@@ -63,13 +63,13 @@ where
fn into_iter(self) -> Self::IntoIter {
match self {
- ProgramControls::Empty => ProgramControlsIter {
+ Self::Empty => ProgramControlsIter {
inner: vec![].into_iter(),
},
- ProgramControls::Single(unit) => ProgramControlsIter {
+ Self::Single(unit) => ProgramControlsIter {
inner: vec![unit].into_iter(),
},
- ProgramControls::Multi(units) => ProgramControlsIter {
+ Self::Multi(units) => ProgramControlsIter {
inner: units.into_iter(),
},
}
@@ -139,17 +139,19 @@ where
RouteToHelp(AnyOutput<C>),
}
-impl<C> From<ChainProcess<C>> for ProgramControlUnit<C>
+impl<C> TryFrom<ChainProcess<C>> for ProgramControlUnit<C>
where
C: ProgramCollect<Enum = C>,
{
- fn from(val: ChainProcess<C>) -> Self {
+ type Error = String;
+
+ fn try_from(val: ChainProcess<C>) -> Result<Self, Self::Error> {
match val {
ChainProcess::Ok((any, next)) => match next {
- NextProcess::Chain => ProgramControlUnit::RouteToChain(any),
- NextProcess::Renderer => ProgramControlUnit::RouteToRender(any),
+ NextProcess::Chain => Ok(Self::RouteToChain(any)),
+ NextProcess::Renderer => Ok(Self::RouteToRender(any)),
},
- ChainProcess::Err(e) => panic!("{}", &e),
+ ChainProcess::Err(e) => Err(e.to_string()),
}
}
}
@@ -159,7 +161,14 @@ where
C: ProgramCollect<Enum = C>,
{
fn from(val: ChainProcess<C>) -> Self {
- let unit: ProgramControlUnit<C> = val.into();
- unit.into()
+ match val {
+ ChainProcess::Ok((any, next)) => match next {
+ NextProcess::Chain => Self::Single(ProgramControlUnit::RouteToChain(any)),
+ NextProcess::Renderer => Self::Single(ProgramControlUnit::RouteToRender(any)),
+ },
+ ChainProcess::Err(e) => Self::Single(ProgramControlUnit::OverrideExitCode(
+ e.to_string().parse::<i32>().unwrap_or(1),
+ )),
+ }
}
}