From 42b5f9e321c918cef542c120ad21ba8a7339eb29 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 25 Jul 2026 12:16:25 +0900 Subject: refactor(operation): replace OperationInterface with AnyOperation enum Operations are only ever constructed by the dependency resolver, so a plugin has no way to inject an implementation of its own and the set is closed. Modelling it as an enum, like AnyPackage, removes the OperationInterface trait together with its two parallel downcast mechanisms (as_any() + downcast_ref, and as_*_operation()) and the get_package() default method that panicked on UpdateOperation. The PHP idiom `$op instanceof UpdateOperation ? getTargetPackage() : getPackage()`, written out at six call sites, becomes AnyOperation::get_target_package(). InstallationManager's three blocks that matched on the type string and then recovered the type with expect() collapse into exhaustive matches. SolverOperation keeps only its TYPE constant; the shared getOperationType()/__toString() implementations move to AnyOperation, which also drops the five Self::TYPE.to_string() allocations. Co-Authored-By: Claude Opus 5 (1M context) --- .../operation/update_operation.rs | 33 ++++++---------------- 1 file changed, 9 insertions(+), 24 deletions(-) (limited to 'crates/shirabe/src/dependency_resolver/operation/update_operation.rs') diff --git a/crates/shirabe/src/dependency_resolver/operation/update_operation.rs b/crates/shirabe/src/dependency_resolver/operation/update_operation.rs index 76b17189..a06a9cdc 100644 --- a/crates/shirabe/src/dependency_resolver/operation/update_operation.rs +++ b/crates/shirabe/src/dependency_resolver/operation/update_operation.rs @@ -1,11 +1,10 @@ //! ref: composer/src/Composer/DependencyResolver/Operation/UpdateOperation.php -use crate::dependency_resolver::operation::OperationInterface; use crate::dependency_resolver::operation::SolverOperation; use crate::package::PackageInterfaceHandle; use crate::package::version::VersionParser; -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct UpdateOperation { pub(crate) initial_package: PackageInterfaceHandle, pub(crate) target_package: PackageInterfaceHandle, @@ -27,6 +26,14 @@ impl UpdateOperation { self.target_package.clone() } + pub fn show(&self, lock: bool) -> String { + Self::format( + self.initial_package.clone(), + self.target_package.clone(), + lock, + ) + } + pub fn format( initial_package: PackageInterfaceHandle, target_package: PackageInterfaceHandle, @@ -78,28 +85,6 @@ impl SolverOperation for UpdateOperation { const TYPE: &'static str = "update"; } -impl OperationInterface for UpdateOperation { - fn as_any(&self) -> &dyn std::any::Any { - self - } - - fn get_operation_type(&self) -> String { - Self::TYPE.to_string() - } - - fn show(&self, lock: bool) -> String { - Self::format( - self.initial_package.clone(), - self.target_package.clone(), - lock, - ) - } - - fn as_update_operation(&self) -> Option<&UpdateOperation> { - Some(self) - } -} - impl std::fmt::Display for UpdateOperation { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!(f, "{}", self.show(false)) -- cgit v1.3.1